﻿<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
	<title xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory">Chapter 7. EPL Reference: Patterns</title>
	<link rel="stylesheet" href="css/espertech.css" type="text/css">
	<meta xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" name="generator" content="DocBook XSL-NS Stylesheets V1.74.0">
	<meta xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link rel="home" href="index.html" title="Esper Reference">
	<link rel="up" href="index.html" title="Esper Reference">
	<link rel="prev" href="nwtable.html" title="Chapter 6. EPL Reference: Named Windows and Tables">
	<link rel="next" href="match-recognize.html" title="Chapter 8. EPL Reference: Match Recognize">
</head>

<body>
	<p xmlns:d="http://docbook.org/ns/docbook" id="title"><a href="./index.html" class="site_href"><strong>www.espertech.com</strong></a><a href="http://www.espertech.com/esper/esper-documentation/" class="doc_href"><strong>Documentation</strong></a></p>
	<ul xmlns:d="http://docbook.org/ns/docbook" class="docnav">
		<li class="previous"><a accesskey="p" href="nwtable.html"><strong>Prev</strong></a></li>
		<li class="next"><a accesskey="n" href="match-recognize.html"><strong>Next</strong></a></li>
	</ul>
	<div class="chapter" lang="en-US">
		<div class="titlepage">
			<div>
				<div>
					<h2 class="title"><a id="event_patterns"></a>Chapter 7. EPL Reference: Patterns</h2>
				</div>
			</div>
		</div>
		<div class="toc">
			<dl>
				<dt><span class="sect1"><a href="event_patterns.html#event-pattern-intro">7.1. Event Pattern Overview</a></span></dt>
				<dt><span class="sect1"><a href="event_patterns.html#pattern-how-to-use">7.2. How to Use Patterns</a></span></dt>
				<dd>
					<dl>
						<dt><span class="sect2"><a href="event_patterns.html#pattern-howto-syntax">7.2.1. Pattern Syntax</a></span></dt>
						<dt><span class="sect2"><a href="event_patterns.html#pattern-in-eql">7.2.2. Patterns in EPL</a></span></dt>
						<dt><span class="sect2"><a href="event_patterns.html#patterns-howto-subscribe">7.2.3. Subscribing to Pattern Events</a></span></dt>
						<dt><span class="sect2"><a href="event_patterns.html#pattern-howto-pull-data">7.2.4. Pulling Data From Patterns</a></span></dt>
						<dt><span class="sect2"><a href="event_patterns.html#pattern-errorreporting">7.2.5. Pattern Error Reporting</a></span></dt>
						<dt><span class="sect2"><a href="event_patterns.html#patterns-howto-suppress">7.2.6. Suppressing Same-Event Matches</a></span></dt>
						<dt><span class="sect2"><a href="event_patterns.html#patterns-howto-discard">7.2.7. Discarding Partially Completed Patterns</a></span></dt>
					</dl>
				</dd>
				<dt><span class="sect1"><a href="event_patterns.html#pattern-op-precedence">7.3. Operator Precedence</a></span></dt>
				<dt><span class="sect1"><a href="event_patterns.html#pattern-filter">7.4. Filter Expressions in Patterns</a></span></dt>
				<dd>
					<dl>
						<dt><span class="sect2"><a href="event_patterns.html#pattern-filter-performance">7.4.1. Filter Expressions and Filter Indexes</a></span></dt>
						<dt><span class="sect2"><a href="event_patterns.html#pattern-filter-consumption">7.4.2. Controlling Event Consumption</a></span></dt>
						<dt><span class="sect2"><a href="event_patterns.html#pattern-filter-namedwindow">7.4.3. Use With Named Windows and Tables</a></span></dt>
					</dl>
				</dd>
				<dt><span class="sect1"><a href="event_patterns.html#pattern-operators">7.5. Pattern Operators</a></span></dt>
				<dd>
					<dl>
						<dt><span class="sect2"><a href="event_patterns.html#pattern-logical-every">7.5.1. Every</a></span></dt>
						<dt><span class="sect2"><a href="event_patterns.html#pattern-logical-everydistinct">7.5.2. Every-Distinct</a></span></dt>
						<dt><span class="sect2"><a href="event_patterns.html#pattern-repeat">7.5.3. Repeat</a></span></dt>
						<dt><span class="sect2"><a href="event_patterns.html#pattern-repeatuntil">7.5.4. Repeat-Until</a></span></dt>
						<dt><span class="sect2"><a href="event_patterns.html#pattern-logical-and">7.5.5. And</a></span></dt>
						<dt><span class="sect2"><a href="event_patterns.html#pattern-logical-or">7.5.6. Or</a></span></dt>
						<dt><span class="sect2"><a href="event_patterns.html#pattern-logical-not">7.5.7. Not</a></span></dt>
						<dt><span class="sect2"><a href="event_patterns.html#pattern-temporal-followed-by">7.5.8. Followed-By</a></span></dt>
						<dt><span class="sect2"><a href="event_patterns.html#pattern-guards">7.5.9. Pattern Guards</a></span></dt>
					</dl>
				</dd>
				<dt><span class="sect1"><a href="event_patterns.html#pattern-atoms">7.6. Pattern Atoms</a></span></dt>
				<dd>
					<dl>
						<dt><span class="sect2"><a href="event_patterns.html#pattern-atom-filter">7.6.1. Filter Atoms</a></span></dt>
						<dt><span class="sect2"><a href="event_patterns.html#pattern-atom-time">7.6.2. Observer Atoms Overview</a></span></dt>
						<dt><span class="sect2"><a href="event_patterns.html#pattern-timer-interval">7.6.3. Interval (timer:interval)</a></span></dt>
						<dt><span class="sect2"><a href="event_patterns.html#pattern-timer-at">7.6.4. Crontab (timer:at)</a></span></dt>
						<dt><span class="sect2"><a href="event_patterns.html#pattern-timer-schedule">7.6.5. Schedule (timer:schedule)</a></span></dt>
					</dl>
				</dd>
				<dt><span class="sect1"><a href="event_patterns.html#pattern-walkthrough">7.7. Event Pattern Walkthrough</a></span></dt>
			</dl>
		</div>
		<div class="sect1" lang="en-US">
			<div class="titlepage">
				<div>
					<div>
						<h2 class="title"><a id="event-pattern-intro"></a>7.1. Event Pattern Overview</h2>
					</div>
				</div>
			</div><a id="d0e19676" class="indexterm"></a>
			<p>
				Event patterns match when an event or multiple events occur that match the pattern's definition. Patterns can also be time-based.
			</p>
			<p>
				Pattern expressions consist of pattern atoms and pattern operators:
			</p>
			<div xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="orderedlist">
				<ol>
					<li>
						<p>
							Pattern <span class="emphasis"><em>atoms</em></span> are the basic building blocks of patterns. Atoms are filter expressions, observers for time-based events and plug-in custom observers that observe external events not under the control of the runtime.
						</p>
					</li>
					<li>
						<p>
							Pattern <span class="emphasis"><em>operators</em></span> control expression lifecycle and combine atoms logically or temporally.
						</p>
					</li>
				</ol>
			</div>
			<p>
				The below table outlines the different pattern atoms available:
			</p>
			<div class="table"><a id="d0e19700"></a>
				<p class="title"><b>Table 7.1. Pattern Atoms</b></p>
				<div class="table-contents">
					<table summary="Pattern Atoms" border="1">
						<colgroup>
							<col>
							<col>
						</colgroup>
						<thead>
							<tr>
								<th>Pattern Atom</th>
								<th>Example</th>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td>Filter expressions specify an event to look for.</td>
								<td>
									<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">StockTick(symbol='ABC', price &gt; 100)</pre>
								</td>
							</tr>
							<tr>
								<td>Time-based event observers specify time intervals or time schedules.</td>
								<td>
									<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">timer:interval(10 seconds)</pre>
									<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">timer:at(*, 16, *, *, *)</pre>
									<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">timer:schedule(....)</pre>
								</td>
							</tr>
							<tr>
								<td>Custom plug-in observers can add pattern language syntax for observing application-specific events.</td>
								<td>
									<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">myapplication:myobserver("http://someResource")</pre>
								</td>
							</tr>
						</tbody>
					</table>
				</div>
			</div><br class="table-break">
			<p>
				There are 4 types of pattern operators:
			</p>
			<div xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="orderedlist">
				<ol>
					<li>
						<p>
							Operators that control pattern sub-expression repetition: <code class="literal">every</code>, <code class="literal">every-distinct</code>, <code class="literal">[num]</code> and <code class="literal">until</code>
						</p>
					</li>
					<li>
						<p>
							Logical operators: <code class="literal">and</code>, <code class="literal">or</code>, <code class="literal">not</code>
						</p>
					</li>
					<li>
						<p>
							Temporal operators that operate on event order: <code class="literal">-&gt;</code> (followed-by)
						</p>
					</li>
					<li>
						<p>
							Guards are where-conditions that control the lifecycle of subexpressions. Examples are <code class="literal">timer:within</code>, <code class="literal">timer:withinmax</code> and <code class="literal">while</code>-expression. Custom plug-in guards may also be used.
						</p>
					</li>
				</ol>
			</div>
			<p>
				Pattern expressions can be nested arbitrarily deep by including the nested expression(s) in <code class="literal">()</code> round parenthesis.
			</p>
			<p>
				Underlying the pattern matching is a hierarchical finite state machine and behavior tree that allocates, transitions and destroys branch and leaf nodes of state based on arriving events and based on time advancing. A single event or advancing time may
				cause a reaction in multiple parts of your active pattern state. Patterns are stateful as the runtime maintains pattern state.
				There is a walkthrough of how a sample pattern behaves in <a class="xref" href="event_patterns.html#pattern-walkthrough" title="7.7. Event Pattern Walkthrough">Section 7.7, “Event Pattern Walkthrough”</a>.
			</p>
		</div>
		<div class="sect1" lang="en-US">
			<div class="titlepage">
				<div>
					<div>
						<h2 class="title"><a id="pattern-how-to-use"></a>7.2. How to Use Patterns</h2>
					</div>
				</div>
			</div>
			<div class="sect2" lang="en-US">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title"><a id="pattern-howto-syntax"></a>7.2.1. Pattern Syntax</h3>
						</div>
					</div>
				</div>
				<p>
					This is an example pattern expression that matches on every <code class="literal">ServiceMeasurement</code> events in which the
					value of the <code class="literal">latency</code> event property is over 20 seconds, and on every <code class="literal">ServiceMeasurement</code> event in which the
					<code class="literal">success</code> property is false. Either one or the other condition must be true for this pattern to match.
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every spike=ServiceMeasurement(latency&gt;20000) 
 or every error=ServiceMeasurement(success=false)</pre>
				<p>
					In the example above, the pattern expression <code class="literal">or</code> operator indicates that the pattern should fire when either of the
					filter expressions fire. The <code class="literal">every</code> operator indicates to fire for every matching event and not just the first
					matching event.
					The left hand of the <code class="literal">or</code> operator filters for events with a high latency value.
					The right hand of the <code class="literal">or</code> operator filters for events with error status.
					Filter expressions are explained in <a class="xref" href="event_patterns.html#pattern-filter" title="7.4. Filter Expressions in Patterns">Section 7.4, “Filter Expressions in Patterns”</a>.
				</p>
				<p>
					The example above assigned the tags <code class="literal">spike</code> and <code class="literal">error</code> to the events in the pattern. The tags are important since the
					runtime only places tagged events into the output event(s) that a pattern generates, and that the runtime supplies to listeners of the pattern statement. The tags can
					further be selected in the select-clause of a statement as discussed in <a class="xref" href="epl_clauses.html#epl-from-clause-patterns" title="5.4.2. Pattern-Based Event Streams">Section 5.4.2, “Pattern-Based Event Streams”</a>.
				</p>
				<p>
					Patterns can also contain comments within the pattern as outlined in <a class="xref" href="epl_clauses.html#epl-syntax-comments" title="5.2.2. Using Comments">Section 5.2.2, “Using Comments”</a>.
				</p>
			</div>
			<div class="sect2" lang="en-US">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title"><a id="pattern-in-eql"></a>7.2.2. Patterns in EPL</h3>
						</div>
					</div>
				</div>
				<p>
					A pattern may appear anywhere in the <code class="literal">from</code> clause of a statement including joins and subqueries. Patterns may therefore be used in combination with the <code class="literal">where</code> clause, <code class="literal">group by</code> clause, <code class="literal">having</code> clause as well as output rate limiting and <code class="literal">insert into</code>.
				</p>
				<p>
					In addition, you may use data window with a pattern. A data window declared for a pattern only serves to retain pattern matches, for use in joins or for iterating via the iterator API. A data window declared onto a pattern does not limit, cancel, remove or delete intermediate pattern matches of the pattern when pattern matches leave the data window.
				</p>
				<p>
					This example statement demonstrates the idea by selecting a total price per customer over pairs of events (ServiceOrder followed by a ProductOrder event for the same customer id within 1 minute), occurring in the last 2 hours, in which the sum of price is greater than 100, and using a <code class="literal">where</code> clause to filter on name:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">select a.custId, sum(a.price + b.price)
from pattern [every a=ServiceOrder -&gt; 
    b=ProductOrder(custId = a.custId) where timer:within(1 min)]#time(2 hour) 
where a.name in ('Repair', b.name)
group by a.custId
having sum(a.price + b.price) &gt; 100</pre>
			</div>
			<div class="sect2" lang="en-US">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title"><a id="patterns-howto-subscribe"></a>7.2.3. Subscribing to Pattern Events</h3>
						</div>
					</div>
				</div>
				<p>
					When a pattern fires it publishes one or more events to any listeners to the pattern statement.
					The listener interface is the <code class="literal">com.espertech.esper.runtime.client.UpdateListener</code> interface.
				</p>
				<p>
					The example below shows an anonymous implementation of the <code class="literal">UpdateListener</code> interface.
					The example adds the anonymous listener implementation to the <code class="literal">myPattern</code> statement created earlier.
					The listener code simply extracts the underlying event class.
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">myPattern.addListener(new UpdateListener() {
  public void update(EventBean[] newEvents, EventBean[] oldEvents, EPStatement statement, EPRuntime runtime) {
    ServiceMeasurement spike = (ServiceMeasurement) newEvents[0].get("spike");
    ServiceMeasurement error = (ServiceMeasurement) newEvents[0].get("error");
    ... // either spike or error can be null, depending on which occurred
    ... // add more logic here
  }
});</pre>
				<p>
					Listeners receive an array of <code class="literal">EventBean</code> instances in the <code class="literal">newEvents</code> parameter.
					There is one <code class="literal">EventBean</code> instance passed to the listener for each combination of events that matches
					the pattern expression. At least one <code class="literal">EventBean</code> instance is always passed to the listener.
				</p>
				<p>
					The properties of each <code class="literal">EventBean</code> instance contain the underlying events that caused the
					pattern to fire, if events have been named in the filter expression via the <code class="literal">name=eventType</code> syntax.
					The property name is thus the name supplied in the pattern expression, while the property type is the type of the underlying class,
					in this example <code class="literal">ServiceMeasurement</code>.
				</p>
			</div>
			<div class="sect2" lang="en-US">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title"><a id="pattern-howto-pull-data"></a>7.2.4. Pulling Data From Patterns</h3>
						</div>
					</div>
				</div>
				<p>
					Data can also be obtained from pattern statements via the <code class="literal">safeIterator()</code> and <code class="literal">iterator()</code> methods on <code class="literal">EPStatement</code> (the pull API)
					If the pattern had fired at least once and the <code class="literal">@IterableUnbound</code> annotation is declared for the statement, then the iterator returns the last event for which it fired.
					The <code class="literal">hasNext()</code> method can then be used to determine if the pattern had fired.
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">if (myPattern.iterator().hasNext()) {
	ServiceMeasurement event = (ServiceMeasurement) statement.iterator().next().get("alert");
    ... // some more code here to process the event
}
else {
    ... // no matching events at this time
}</pre>
				<p>
					Further, if a data window is defined onto a pattern, the iterator returns the pattern matches according to the data window expiry policy.
				</p>
				<p>
					This pattern specifies a length window of 10 elements that retains the last 10 matches of A and B events, for use via iterator or for use in a join or subquery:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">select * from pattern [every (A or B)]#length(10)</pre>
			</div>
			<div class="sect2" lang="en-US">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title"><a id="pattern-errorreporting"></a>7.2.5. Pattern Error Reporting</h3>
						</div>
					</div>
				</div>
				<p>
					While the pattern compiler analyzes your pattern and verifies its integrity, it may not detect certain pattern errors that may occur at runtime. Sections of this pattern documentation
					point out common cases where the pattern runtime will log a runtime error. We recommend turning on the log warning level at project development time to inspect and report on warnings logged.
					If a statement name is assigned to a statement then the statement name is logged as well.
				</p>
			</div>
			<div class="sect2" lang="en-US">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title"><a id="patterns-howto-suppress"></a>7.2.6. Suppressing Same-Event Matches</h3>
						</div>
					</div>
				</div>
				<p>
					Any given event can contribute to multiple matches.
				</p>
				<p>
					For example, consider the following pattern:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every a=A -&gt; B</pre>
				<p>
					Given this sequence of events:
				</p>
				<p>
					A<sub>1</sub>  
					A<sub>2</sub>  
					B<sub>1</sub>  
				</p>
				<p>
					When event B<sub>1</sub> arrives the pattern matches for both the combination {A<sub>1</sub>, B<sub>1</sub>}
					and the combination {A<sub>2</sub>, B<sub>1</sub>}.
					The runtime indicates both matches to the listener or subscriber by delivering an array containing both matches in a single listener or subscriber invocation.
				</p>
				<p>
					Use the <code class="literal">@SuppressOverlappingMatches</code> pattern-level annotation to instruct the runtime to discard all but the first match among multiple overlapping matches.
				</p>
				<p>
					The same example with the pattern-level annotation is:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">select * from pattern @SuppressOverlappingMatches [every a=A -&gt; b=B]</pre>
				<p>
					When event B<sub>1</sub> arrives the pattern outputs only the first combination that matches, namely the combination {A<sub>1</sub>, B<sub>1</sub>}.
					The runtime discards the second combination ({A<sub>2</sub>, B<sub>1</sub>}) that matches as it detects that event B<sub>1</sub>
					overlaps between the first and the second match.
				</p>
				<div xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="note">
					<h2>Note</h2>
					<div class="itemizedlist">
						<ul>
							<li>The runtime only considers tagged events for detecting overlap.</li>
							<li>Suppression takes place among multiple simultaneously occurring matches as a result of a single event arriving or time advancing.</li>
							<li>Partially completed patterns are not impacted and existing pattern state does not change as a result of suppression.</li>
							<li>Limitation: The annotation cannot be used with patterns in joins.</li>
						</ul>
					</div>
				</div>
			</div>
			<div class="sect2" lang="en-US">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title"><a id="patterns-howto-discard"></a>7.2.7. Discarding Partially Completed Patterns</h3>
						</div>
					</div>
				</div>
				<p>
					Partially-completed patterns are incomplete matches that are not yet indicated by the runtime because the complete pattern condition is not satisfied.
					Any given event can be part of multiple partially-completed patterns.
				</p>
				<p>
					For example, consider the following pattern:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every a=A -&gt; B and C(id=a.id)</pre>
				<p>
					Given this sequence of events:
				</p>
				<p>
					A<sub>1</sub>{id='id1'}  
					A<sub>2</sub>{id='id2'}  
					B<sub>1</sub>  
				</p>
				<p>
					According to the sequence above there are no matches. The pattern is partially completed waiting for C events.
					The combination {A<sub>1</sub>, B<sub>1</sub>} is waiting for a C{id='id1'} event before the pattern match is complete for that combination.
					The combination {A<sub>2</sub>, B<sub>1</sub>} is waiting for a C{id='id2'} event before the pattern match is complete for that combination.
				</p>
				<p>
					Assuming event C<sub>1</sub>{id='id1') arrives the pattern outputs the combination {A<sub>1</sub>, B<sub>1</sub>, C<sub>1</sub>}.
					Assuming event C<sub>2</sub>{id='id2') arrives the pattern outputs the combination {A<sub>2</sub>, B<sub>1</sub>, C<sub>2</sub>}.
					Note that event B<sub>1</sub> is part of both partially-completed patterns.
				</p>
				<p>
					Use the <code class="literal">@DiscardPartialsOnMatch</code> pattern-level annotation to instruct the runtime that when any matches occur to discard partially completed patterns that overlap in terms of the events that
					make up the match (or matches if there are multiple matches).
				</p>
				<p>
					The same example using the <code class="literal">@DiscardPartialsOnMatch</code> pattern-level annotation is:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">select * from pattern @DiscardPartialsOnMatch [every a=A -&gt; B and C(id=a.id)]</pre>
				<p>
					When event C<sub>1</sub>{id='id1') arrives the pattern outputs the match combination {A<sub>1</sub>, B<sub>1</sub>, C<sub>1</sub>}.
					Upon indication of the match the runtime discards all partially-completed patterns that refer to either of the A<sub>1</sub>, B<sub>1</sub> and C<sub>1</sub> events.
					Since event B<sub>1</sub> is part of a partially-completed pattern waiting for C{id='id2'}, the runtime discards that partially-completed pattern.
					Therefore when C<sub>2</sub>{id='id2'} arrives the runtime outputs no matches.
				</p>
				<p>
					When specifying both <code class="literal">@DiscardPartialsOnMatch</code> and <code class="literal">@SuppressOverlappingMatches</code> the runtime discards the partially-completed patterns that overlap all matches including suppressed matches.
				</p>
				<div xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="note">
					<h2>Note</h2>
					<div class="itemizedlist">
						<ul>
							<li>The runtime only considers tagged events for detecting overlap.</li>
							<li>Only partially completed patterns are impacted.</li>
							<li>Limitation: The annotation cannot be used with patterns in joins.</li>
							<li>Limitation: Removing partially completed patterns is not an undo operation.
								There is no reversal in truth-value, i.e. past matches are not retracted or indicated as a remove stream.
								The <code class="literal">not</code> operator can change truth value to permanently false.
								The change in truth-value does not get reversed when a match removes the event that caused the <code class="literal">not</code> operator to become permanently false.
							</li>
						</ul>
					</div>
				</div>
			</div>
		</div>
		<div class="sect1" lang="en-US">
			<div class="titlepage">
				<div>
					<div>
						<h2 class="title"><a id="pattern-op-precedence"></a>7.3. Operator Precedence</h2>
					</div>
				</div>
			</div><a id="d0e20164" class="indexterm"></a>
			<p>
				The operators at the top of this table take precedence over operators lower on the table.
			</p>
			<div class="table"><a id="d0e20171"></a>
				<p class="title"><b>Table 7.2. Pattern Operator Precedence</b></p>
				<div class="table-contents">
					<table summary="Pattern Operator Precedence" border="1">
						<colgroup>
							<col>
							<col>
							<col>
							<col>
						</colgroup>
						<thead>
							<tr>
								<th>Precedence</th>
								<th>Operator</th>
								<th>Description</th>
								<th>Example</th>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td>1</td>
								<td>guard postfix</td>
								<td><code class="literal">where timer:within</code> and <code class="literal">while (expression)</code> (incl. withinmax and plug-in pattern guard)</td>
								<td>
									<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">MyEvent where timer:within(1 sec)</pre>
									<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">a=MyEvent while (a.price between 1 and 10)</pre>
								</td>
							</tr>
							<tr>
								<td>2</td>
								<td>unary</td>
								<td><code class="literal">every, not, every-distinct</code></td>
								<td>
									<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every MyEvent
timer:interval(5 min) and not MyEvent</pre>
								</td>
							</tr>
							<tr>
								<td>3</td>
								<td>repeat</td>
								<td><code class="literal">[num]</code>, <code class="literal">until</code></td>
								<td>
									<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">[5] MyEvent</pre>
									<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">[1..3] MyEvent until MyOtherEvent</pre>
								</td>
							</tr>
							<tr>
								<td>4</td>
								<td>and</td>
								<td><code class="literal">and</code></td>
								<td>
									<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every (MyEvent and MyOtherEvent)</pre>
								</td>
							</tr>
							<tr>
								<td>5</td>
								<td>or</td>
								<td><code class="literal">or</code></td>
								<td>
									<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every (MyEvent or MyOtherEvent)</pre>
								</td>
							</tr>
							<tr>
								<td>6</td>
								<td>followed-by</td>
								<td><code class="literal">-&gt;</code></td>
								<td>
									<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every (MyEvent -&gt; MyOtherEvent)</pre>
								</td>
							</tr>
						</tbody>
					</table>
				</div>
			</div><br class="table-break">
			<p>
				If you are not sure about the precedence, please consider placing parenthesis <code class="literal">()</code> around your subexpressions. Parenthesis can also help make
				expressions easier to read and understand.
			</p>
			<p>
				The following table outlines sample equivalent expressions, with and without the use of parenthesis for subexpressions.
			</p>
			<div class="table"><a id="d0e20280"></a>
				<p class="title"><b>Table 7.3. Equivalent Pattern Expressions</b></p>
				<div class="table-contents">
					<table summary="Equivalent Pattern Expressions" border="1">
						<colgroup>
							<col>
							<col>
							<col>
						</colgroup>
						<thead>
							<tr>
								<th>Expression</th>
								<th>Equivalent</th>
								<th>Reason</th>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td>every A or B</td>
								<td>(every A) or B</td>
								<td>The <code class="literal">every</code> operator has higher precedence then the <code class="literal">or</code> operator.</td>
							</tr>
							<tr>
								<td>every A -&gt; B or C</td>
								<td>(every A) -&gt; (B or C)</td>
								<td>The <code class="literal">or</code> operator has higher precedence then the <code class="literal">followed-by</code> operator.</td>
							</tr>
							<tr>
								<td>A -&gt; B or B -&gt; A</td>
								<td>A -&gt; (B or B) -&gt; A</td>
								<td>The <code class="literal">or</code> operator has higher precedence then the <code class="literal">followed-by</code> operator,
									specify as (A -&gt; B) or (B -&gt; A) instead.
								</td>
							</tr>
							<tr>
								<td>A and B or C</td>
								<td>(A and B) or C</td>
								<td>The <code class="literal">and</code> operator has higher precedence then the <code class="literal">or</code> operator.</td>
							</tr>
							<tr>
								<td>A -&gt; B until C -&gt; D</td>
								<td>A -&gt; (B until C) -&gt; D</td>
								<td>The <code class="literal">until</code> operator has higher precedence then the <code class="literal">followed-by</code> operator.</td>
							</tr>
							<tr>
								<td>[5] A or B </td>
								<td>([5] A) or B</td>
								<td>The <code class="literal">[num]</code> repeat operator has higher precedence then the <code class="literal">or</code> operator.</td>
							</tr>
							<tr>
								<td>every A where timer:within(10)</td>
								<td>every (A where timer:within(10))</td>
								<td>The <code class="literal">where</code> postfix has higher precedence then the <code class="literal">every</code> operator.</td>
							</tr>
						</tbody>
					</table>
				</div>
			</div><br class="table-break">
		</div>
		<div class="sect1" lang="en-US">
			<div class="titlepage">
				<div>
					<div>
						<h2 class="title"><a id="pattern-filter"></a>7.4. Filter Expressions in Patterns</h2>
					</div>
				</div>
			</div><a id="d0e20390" class="indexterm"></a>
			<p>
				The simplest form of filter is a filter for events of a given type without any conditions on the event property values. This filter matches any event of that type regardless of the event's properties. The example below is such a filter. Note that this event pattern would stop firing as soon as the first RfidEvent is encountered.
			</p>
			<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">com.mypackage.myevents.RfidEvent</pre>
			<p>
				To make the event pattern fire for every RfidEvent and not just the first event, use the <code class="literal">every</code> keyword.
			</p>
			<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every com.mypackage.myevents.RfidEvent</pre>
			<p>
				The example above specifies the fully-qualified Java class name as the event type. Via configuration, the event pattern above can be simplified by using the name
				that has been defined for the event type.
			</p>
			<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every RfidEvent</pre>
			<p>
				Interfaces and superclasses are also supported as event types. In the below example <code class="literal">IRfidReadable</code> is an interface class, and the statement matches any event that implements this interface:
			</p>
			<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every org.myorg.rfid.IRfidReadable</pre>
			<p>
				The filtering criteria to filter for events with certain event property values are placed within parenthesis after the event type name:
			</p>
			<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">RfidEvent(category="Perishable")</pre>
			<p>
				All expressions can be used in filters, including static method invocations that return a boolean value:
			</p>
			<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">RfidEvent(com.mycompany.MyRFIDLib.isInRange(x, y) or (x&lt;0 and y &lt; 0))</pre>
			<p>
				Filter expressions can be separated via a single comma '<code class="literal">,</code>'. The comma represents a logical AND between expressions:
			</p>
			<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">RfidEvent(zone=1, category=10)
...is equivalent to...
RfidEvent(zone=1 and category=10)</pre>
			<p>
				For more information on filters please see <a class="xref" href="epl_clauses.html#epl-from-clause-filter" title="5.4.1. Filter-Based Event Streams">Section 5.4.1, “Filter-Based Event Streams”</a>. Contained-event selection on filters in patterns is further described in <a class="xref" href="epl_clauses.html#epl-containedeventselect" title="5.19. Contained-Event Selection">Section 5.19, “Contained-Event Selection”</a>.
			</p>
			<p>
				Filter criteria can also refer to events matching prior named events in the same expression. Below pattern is an example in which the pattern
				matches once for every RfidEvent that is preceded by an RfidEvent with the same asset id.
			</p>
			<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every e1=RfidEvent -&gt; e2=RfidEvent(assetId=e1.assetId)</pre>
			<p>
				The syntax shown above allows filter criteria to reference prior results by specifying the event name tag of the prior event, and the event property name. The tag names in the above example were <code class="literal">e1</code> and <code class="literal">e2</code>. This syntax can be used in all filter operators or expressions including ranges and the <code class="literal">in</code> set-of-values check:
			</p>
			<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every e1=RfidEvent -&gt; 
  e2=RfidEvent(MyLib.isInRadius(e1.x, e1.y, x, y) and zone in (1, e1.zone))</pre>
			<p>
				An arriving event changes the truth value of all expressions that look for the event. Consider the pattern as follows:
			</p>
			<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every (RfidEvent(zone &gt; 1) and RfidEvent(zone &lt; 10))</pre>
			<p>
				The pattern above is satisfied as soon as only one event with zone in the interval [2, 9] is received.
			</p>
			<div class="sect2" lang="en-US">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title"><a id="pattern-filter-performance"></a>7.4.1. Filter Expressions and Filter Indexes</h3>
						</div>
					</div>
				</div>
				<div xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="important">
					<h2>Important</h2>
					<p>
						A detailed description of how filters become active and are indexed is provided at <a class="xref" href="processingmodel.html#processingmodel_indexes_filterindexes_pattern" title="2.18.2.2. Filter Index Pattern Example">Section 2.18.2.2, “Filter Index Pattern Example”</a>.
					</p>
					<p>
						An expression such as <code class="literal">a=A -&gt; B(id=a.id)</code> (A followed-by B with the same id as A) is not just a state change, in fact the runtime registers new B-filter instances dynamically and in runtime-wide shared filter indexes.
						This means that while such a pattern seems to be slow if you are sending A-events, the runtime can filter, match or discard B-events very fast as for B-events it only needs to perform a lookup in filter indexes.
						If you are looking for best performance and don't expect to need filter indexes, or if you compare to another technology that doesn't have the concept of filter indexes, please use match-recognize instead.
					</p>
				</div>
				<p>
					The runtime analyzes all filter expressions within a pattern and determines the filter indexes to use or to create. Indexing filter values to match event properties of incoming events enables the runtime to match incoming events faster to pattern subexpressions.
				</p>
				<p>
					More information on filter indexes in general can be found at <a class="xref" href="processingmodel.html#processingmodel_indexes_filterindexes" title="2.18.2. Filter Indexes">Section 2.18.2, “Filter Indexes”</a>.
				</p>
				<p>
					More information on the operators relevant to filter indexes can be found at <a class="xref" href="epl_clauses.html#epl-filter-criteria" title="5.4.1.2. Specifying Filter Criteria">Section 5.4.1.2, “Specifying Filter Criteria”</a>.
				</p>
			</div>
			<div class="sect2" lang="en-US">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title"><a id="pattern-filter-consumption"></a>7.4.2. Controlling Event Consumption</h3>
						</div>
					</div>
				</div><a id="d0e20487" class="indexterm"></a>
				<p>
					An arriving event applies to all filter expressions for which the event matches. In other words, an arriving event is not consumed by any specify filter expression(s) but applies to all active filter expressions of all pattern sub-expressions.
				</p>
				<p>
					You may provide the <code class="literal">@consume</code> annotation as part of a filter expression to control consumption of an arriving event. If an arriving event matches the filter expression marked with <code class="literal">@consume</code> it
					is no longer available to other filter expressions of the same pattern that also match the arriving event.
				</p>
				<p>
					The <code class="literal">@consume</code> can include a level number in parenthesis. A higher level number consumes the event first. The default level number is 1. Multiple filter expressions with the same level number for <code class="literal">@consume</code> all match the event.
				</p>
				<p>
					Consider the next sample pattern:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">a=RfidEvent(zone='Z1') and b=RfidEvent(assetId='0001')</pre>
				<p>
					This pattern fires when a single RfidEvent event arrives that has zone 'Z1' and assetId '0001'. The pattern also matches
					when two RfidEvent events arrive, in any order, wherein one has zone 'Z1' and the other has assetId '0001'.
				</p>
				<p>
					Mark a filter expression with <code class="literal">@consume</code> to indicate that if an arriving event matches multiple filter expressions that the runtime prefers the marked filter expression and does not match any other filter expression.
				</p>
				<p>
					This updated pattern statement uses <code class="literal">@consume</code> to indicate that a match against zone is preferred:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">a=RfidEvent(zone='Z1')@consume and b=RfidEvent(assetId='0001')</pre>
				<p>
					This pattern no longer fires when a single RfidEvent arrives that has zone 'Z1' and assetId '0001', because when the first filter expression matches the pattern runtime consumes the event.
					The pattern only matches when two RfidEvent events arrive in any order. One event must have zone 'Z1' and the other event must have a zone other than 'Z1' and an assetId '0001'.
				</p>
				<p>
					The next sample pattern provides a level number for each <code class="literal">@consume</code>:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">a=RfidEvent(zone='Z1')@consume(2) 
  or b=RfidEvent(assetId='0001')@consume(1) 
  or c=RfidEvent(category='perishable'))</pre>
				<p>
					The pattern fires when an RfidEvent arrives with zone 'Z1'. In this case the output event populates property 'a' but not properties 'b' and 'c'.
					The pattern also fires when an RfidEvent arrives with a zone other than 'Z1' and an asset id of '0001'. In this case the output event populates property 'b' but not properties 'a' and 'c'.
					The pattern also fires when an RfidEvent arrives with a zone other than 'Z1' and an asset id other than '0001' and a category of 'perishable'. In this case the output event populates property 'c' but not properties 'a' and 'b'.
				</p>
			</div>
			<div class="sect2" lang="en-US">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title"><a id="pattern-filter-namedwindow"></a>7.4.3. Use With Named Windows and Tables</h3>
						</div>
					</div>
				</div><a id="d0e20542" class="indexterm"></a><a id="d0e20547" class="indexterm"></a>
				<p>
					When your filter expression provides the name of a named window then the filter expression matches each time an event is inserted into the named window that matches the filter conditions.
				</p>
				<p>
					For example, assume a named window that holds the last order event per order id:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">create window LastOrderWindow#unique(orderId) as OrderEvent</pre>
				<p>
					Assume that all order events are inserted into the named window using insert-into:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">insert into LastOrderWindow select * from OrderEvent</pre>
				<p>
					This sample pattern fires 10 seconds after an order event with a price greater then 100 was inserted:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">select * from pattern [every o=LastOrderWindow(price &gt;= 100) -&gt; timer:interval(10 sec)]</pre>
				<p>
					The pattern above fires only for events inserted-into the <code class="literal">LastOrderWindow</code> named window and does not fire when an order event was updated using on-update or merged using on-merge.
				</p>
				<p>
					If your application would like to have the pattern fire for any change to the named window events including updates and merges, you must select from the named window as follows:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">insert into OrderWindowChangeStream select * from LastOrderWindow</pre>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">select * from pattern [every o=OrderWindowChangeStream(price &gt;= 100) -&gt; timer:interval(10 sec)]</pre>
				<p>
					A table cannot be listed as part of a pattern filter, however any filter EPL expressions can have tables access expressions and subqueries against tables.
				</p>
				<p>
					Assuming that <code class="literal">MyTable</code> is a table, the following is not allowed:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">// not allowed
select * from pattern [every MyTable -&gt; timer:interval(10 sec)]</pre>
			</div>
		</div>
		<div class="sect1" lang="en-US">
			<div class="titlepage">
				<div>
					<div>
						<h2 class="title"><a id="pattern-operators"></a>7.5. Pattern Operators</h2>
					</div>
				</div>
			</div>
			<div class="sect2" lang="en-US">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title"><a id="pattern-logical-every"></a>7.5.1. Every</h3>
						</div>
					</div>
				</div><a id="d0e20592" class="indexterm"></a><a id="d0e20597" class="indexterm"></a>
				<p>
					The <code class="literal">every</code> operator indicates that the pattern sub-expression should restart when the subexpression qualified by the <code class="literal">every</code> keyword evaluates to true or false.
					Without the <code class="literal">every</code> operator the pattern sub-expression stops when the pattern sub-expression evaluates to true or false.
				</p>
				<p>
					As a side note, please be aware that a single invocation to the <code class="literal">UpdateListener</code> interface may deliver multiple events in one invocation, since the interface accepts an array of values.
				</p>
				<p>
					Thus the <code class="literal">every</code> operator works like a factory for the pattern sub-expression contained within. When the pattern sub-expression within it fires and thus quits checking for events, the <code class="literal">every</code> causes the start of a new pattern sub-expression listening for more occurrences of the same
					event or set of events.
				</p>
				<p>
					Every time a pattern sub-expression within an <code class="literal">every</code> operator turns true the runtime starts a new active subexpression looking
					for more event(s) or timing conditions that match the pattern sub-expression. If the <code class="literal">every</code> operator is not specified for a subexpression,
					the subexpression stops after the first match was found.
				</p>
				<p>
					This pattern fires when encountering an A event and then stops looking.
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">A</pre>
				<p>
					This pattern keeps firing when encountering A events, and doesn't stop looking.
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every A</pre>
				<p>
					When using <code class="literal">every</code> operator with the <code class="literal">-&gt;</code> followed-by operator, each time the <code class="literal">every</code> operator restarts it also starts a new subexpression instance looking for events in the followed-by subexpression.
				</p>
				<p>
					Let's consider an example event sequence as follows.
				</p>
				<p>
					A<sub>1</sub>  
					B<sub>1</sub>  
					C<sub>1</sub>  
					B<sub>2</sub>  
					A<sub>2</sub>  
					D<sub>1</sub>  
					A<sub>3</sub>  
					B<sub>3</sub>  
					E<sub>1</sub>  
					A<sub>4</sub>  
					F<sub>1</sub>  
					B<sub>4</sub>
				</p>
				<div class="table"><a id="pattern-every-samples"></a>
					<p class="title"><b>Table 7.4. <code class="literal">Every</code> Operator Examples</b></p>
					<div class="table-contents">
						<table summary="Every Operator Examples" border="1">
							<colgroup>
								<col>
								<col>
							</colgroup>
							<thead>
								<tr>
									<th>Example</th>
									<th>Description</th>
								</tr>
							</thead>
							<tbody>
								<tr>
									<td>
										<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every ( A -&gt; B )</pre>
									</td>
									<td>
										<p>
											Detect an A event followed by a B event.
											At the time when B occurs the pattern matches, then the pattern matcher restarts and looks for the next A event.
										</p>
										<div xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="orderedlist">
											<ol>
												<li>
													<p>
														Matches on B<sub>1</sub> for combination {A<sub>1</sub>, B<sub>1</sub>}
													</p>
												</li>
												<li>
													<p>
														Matches on B<sub>3</sub> for combination {A<sub>2</sub>, B<sub>3</sub>}
													</p>
												</li>
												<li>
													<p>
														Matches on B<sub>4</sub> for combination {A<sub>4</sub>, B<sub>4</sub>}
													</p>
												</li>
											</ol>
										</div>
									</td>
								</tr>
								<tr>
									<td>
										<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every A -&gt; B</pre>
									</td>
									<td>
										<p>
											The pattern fires for every A event followed by a B event.
										</p>
										<div xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="orderedlist">
											<ol>
												<li>
													<p>
														Matches on B<sub>1</sub> for combination {A<sub>1</sub>, B<sub>1</sub>}
													</p>
												</li>
												<li>
													<p>
														Matches on B<sub>3</sub> for combination {A<sub>2</sub>, B<sub>3</sub>}
														and {A<sub>3</sub>, B<sub>3</sub>}
													</p>
												</li>
												<li>
													<p>
														Matches on B<sub>4</sub> for combination {A<sub>4</sub>, B<sub>4</sub>}
													</p>
												</li>
											</ol>
										</div>
									</td>
								</tr>
								<tr>
									<td>
										<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">A -&gt; every B</pre>
									</td>
									<td>
										<p>
											The pattern fires for an A event followed by every B event.
										</p>
										<div xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="orderedlist">
											<ol>
												<li>
													<p>
														Matches on B<sub>1</sub> for combination {A<sub>1</sub>, B<sub>1</sub>}.
													</p>
												</li>
												<li>
													<p>
														Matches on B<sub>2</sub> for combination {A<sub>1</sub>, B<sub>2</sub>}.
													</p>
												</li>
												<li>
													<p>
														Matches on B<sub>3</sub> for combination {A<sub>1</sub>, B<sub>3</sub>}
													</p>
												</li>
												<li>
													<p>
														Matches on B<sub>4</sub> for combination {A<sub>1</sub>, B<sub>4</sub>}
													</p>
												</li>
											</ol>
										</div>
									</td>
								</tr>
								<tr>
									<td>
										<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every A -&gt; every B</pre>
									</td>
									<td>
										<p>
											The pattern fires for every A event followed by every B event.
										</p>
										<div xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="orderedlist">
											<ol>
												<li>
													<p>
														Matches on B<sub>1</sub> for combination {A<sub>1</sub>, B<sub>1</sub>}.
													</p>
												</li>
												<li>
													<p>
														Matches on B<sub>2</sub> for combination {A<sub>1</sub>, B<sub>2</sub>}.
													</p>
												</li>
												<li>
													<p>
														Matches on B<sub>3</sub> for combination {A<sub>1</sub>, B<sub>3</sub>}
														and {A<sub>2</sub>, B<sub>3</sub>} and {A<sub>3</sub>, B<sub>3</sub>}
													</p>
												</li>
												<li>
													<p>
														Matches on B<sub>4</sub> for combination {A<sub>1</sub>, B<sub>4</sub>}
														and {A<sub>2</sub>, B<sub>4</sub>} and {A<sub>3</sub>, B<sub>4</sub>}
														and {A<sub>4</sub>, B<sub>4</sub>}
													</p>
												</li>
											</ol>
										</div>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
				</div><br class="table-break">
				<p>
					The examples show that it is possible that a pattern fires for multiple combinations of events that match a pattern expression.
					Each combination is posted as an <code class="literal">EventBean</code> instance to the <code class="literal">update</code> method in the <code class="literal">UpdateListener</code> implementation.
				</p>
				<p>
					Let's consider the <code class="literal">every</code> operator in conjunction with a subexpression that matches 3 events that follow each other:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every (A -&gt; B -&gt; C)</pre>
				<p>
					The pattern first looks for A events. When an A event arrives, it looks for a B event. After the B event arrives, the pattern looks for a C event. Finally, when the C event arrives the pattern fires. The runtime then starts looking for an A event again.
				</p>
				<p>
					Assume that between the B event and the C event a second A<sub>2</sub> event arrives. The pattern would ignore the A<sub>2</sub> event entirely since it's then looking for a C event.
					As observed in the prior example, the <code class="literal">every</code> operator restarts the subexpression <code class="literal">A -&gt; B -&gt; C</code> only when the subexpression fires.
				</p>
				<p>
					In the next statement the <code class="literal">every</code> operator applies only to the A event, not the whole subexpression:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every A -&gt; B -&gt; C</pre>
				<p>
					This pattern now matches for each A event that is followed by a B event and then a C event, regardless of when the A event arrives. Note that for each A event that arrives the pattern runtime starts a new subexpression looking for a B event and then a C event, outputting each combination of matching events.
				</p>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-every-equivanence"></a>7.5.1.1. <code class="literal">Every</code> Operator Equivalence</h4>
							</div>
						</div>
					</div>
					<p>
						A pattern that only has the <code class="literal">every</code> operator and a single filter expression is equivalent to selecting the same filter in the <code class="literal">from</code> clause:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">select * from StockTickEvent(symbol='GE')	     // Prefer this
// ... equivalent to ...
select * from pattern[every StockTickEvent(symbol='GE')]</pre>
				</div>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-every-ending-subexp"></a>7.5.1.2. Limiting Subexpression Lifetime</h4>
							</div>
						</div>
					</div>
					<p>
						As the introduction of the <code class="literal">every</code> operator states, the operator starts new subexpression instances and can cause multiple matches to occur for a single arriving event.
					</p>
					<p>
						New subexpressions also take a very small amount of system resources and thereby your application should carefully consider when subexpressions must end when designing patterns. Use the <code class="literal">timer:within</code> construct and the <code class="literal">and not</code> constructs to end active subexpressions. The data window onto a pattern stream does not serve to limit pattern sub-expression lifetime.
					</p>
					<p>
						Lets look at a concrete example. Consider the following sequence of events arriving:
					</p>
					<p>
						A<sub>1</sub>  
						A<sub>2</sub>  
						B<sub>1</sub>  
					</p>
					<p>
						This pattern matches on arrival of B<sub>1</sub> and outputs two events (an array of length 2 if using a listener). The two events are the combinations {A<sub>1</sub>, B<sub>1</sub>} and {A<sub>2</sub>, B<sub>1</sub>}:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every a=A -&gt; b=B</pre>
					<p>
						The <code class="literal">and not</code> operators are used to end an active subexpression.
					</p>
					<p>
						The next pattern matches on arrival of B<sub>1</sub> and outputs only the last A event which is the combination {A<sub>2</sub>, B<sub>1</sub>}:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every a=A -&gt; (b=B and not A)</pre>
					<p>
						The <code class="literal">and not</code> operators cause the subexpression looking for {A<sub>1</sub>, B?} to end when A<sub>2</sub> arrives.
					</p>
					<p>
						Similarly, in the pattern below the runtime starts a new subexpression looking for a B event every 1 second. After 5 seconds there are 5 subexpressions active looking for a B event and 5 matches occur at once if a B event arrives after 5 seconds.
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every timer:interval(1 sec) -&gt; b=B</pre>
					<p>
						Again the <code class="literal">and not</code> operators can end subexpressions that are not intended to match any longer:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every timer:interval(1 sec) -&gt; (b=B and not timer:interval(1 sec))
// equivalent to
every timer:interval(1 sec) -&gt; (b=B where timer:within(1 sec))</pre>
				</div>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-every-sample1"></a>7.5.1.3. <code class="literal">Every</code> Operator Example</h4>
							</div>
						</div>
					</div>
					<p>
						This example considers a generic pattern in which the pattern must match for each A event followed by a B event and followed by a C event, in which both the B event and the C event must arrive within 1 hour of the A event. The first approach to the pattern is as follows:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every A  -&gt; (B -&gt; C) where timer:within(1 hour)</pre>
					<p>
						Consider the following sequence of events arriving:
					</p>
					<p>
						A<sub>1</sub>  
						A<sub>2</sub>  
						B<sub>1</sub>  
						C<sub>1</sub>  
						B<sub>2</sub>  
						C<sub>2</sub>
					</p>
					<p>
						First, the pattern as above never stops looking for A events since the <code class="literal">every</code> operator instructs the pattern to keep looking for A events.
					</p>
					<p>
						When A<sub>1</sub> arrives, the pattern starts a new subexpression that keeps A<sub>1</sub> in memory and looks for any B event. At the same time, it also keeps looking for more A events.
					</p>
					<p>
						When A<sub>2</sub> arrives, the pattern starts a new subexpression that keeps A<sub>2</sub> in memory and looks for any B event. At the same time, it also keeps looking for more A events.
					</p>
					<p>
						After the arrival of A<sub>2</sub>, there are 3 subexpressions active:
					</p>
					<div xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="orderedlist">
						<ol>
							<li>
								<p>
									The first active subexpression with A<sub>1</sub> in memory, looking for any B event.
								</p>
							</li>
							<li>
								<p>
									The second active subexpression with A<sub>2</sub> in memory, looking for any B event.
								</p>
							</li>
							<li>
								<p>
									A third active subexpression, looking for the next A event.
								</p>
							</li>
						</ol>
					</div>
					<p>
						In the pattern above, there is a 1-hour lifetime for subexpressions looking for B and C events. Thus, if no B and no C event arrive within 1 hour after A<sub>1</sub>, the first subexpression goes away. If no B and no C event arrive within 1 hour after A<sub>2</sub>, the second subexpression goes away. The third subexpression however stays around looking for more A events.
					</p>
					<p>
						The pattern as shown above thus matches on arrival of C<sub>1</sub> for combination {A<sub>1</sub>, B<sub>1</sub>, C<sub>1</sub>} and
						for combination {A<sub>2</sub>, B<sub>1</sub>, C<sub>1</sub>}, provided that B<sub>1</sub> and C<sub>1</sub> arrive within an hour of A<sub>1</sub> and A<sub>2</sub>.
					</p>
					<p>
						You may now ask how to match on {A<sub>1</sub>, B<sub>1</sub>, C<sub>1</sub>} and {A<sub>2</sub>, B<sub>2</sub>, C<sub>2</sub>} instead, since
						you may need to correlate on a given property.
					</p>
					<p>
						The pattern as discussed above matches every A event followed by the first B event followed by the next C event, and doesn't specifically qualify the B or C events to look for based on the A event. To look for specific B and C events in relation to a given A event, specify correlating properties of the A event, for example:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every a=A -&gt; (B(id=a.id) -&gt; C(id=a.id)) where timer:within(1 hour)</pre>
					<p>
						The pattern as shown above thus matches on arrival of C<sub>1</sub> for combination {A<sub>1</sub>, B<sub>1</sub>, C<sub>1</sub>} and
						on arrival of C<sub>2</sub> for combination {A<sub>2</sub>, B<sub>2</sub>, C<sub>2</sub>}.
					</p>
				</div>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-every-sample2"></a>7.5.1.4. Sensor Example</h4>
							</div>
						</div>
					</div>
					<p>
						This example looks at temperature sensor events named Sample. The pattern detects when 3 sensor events indicate a temperature of more then 50 degrees uninterrupted within 90 seconds of the first event, considering events for the same sensor only.
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every sample=Sample(temp &gt; 50) -&gt;
( (Sample(sensor=sample.sensor, temp &gt; 50) and not Sample(sensor=sample.sensor, temp &lt;= 50))   
  -&gt;
  (Sample(sensor=sample.sensor, temp &gt; 50) and not Sample(sensor=sample.sensor, temp &lt;= 50))   
 ) where timer:within(90 seconds))</pre>
					<p>
						The pattern starts a new subexpression in the round braces after the first followed-by operator for each time a sensor indicated more then 50 degrees. Each subexpression then lives a maximum of 90 seconds. Each subexpression ends if a temperature of 50 degress or less is encountered for the same sensor. Only if 3 temperature events in a row indicate more then 50 degrees, and within 90 seconds of the first event, and for the same sensor, does this pattern fire.
					</p>
				</div>
			</div>
			<div class="sect2" lang="en-US">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title"><a id="pattern-logical-everydistinct"></a>7.5.2. Every-Distinct</h3>
						</div>
					</div>
				</div><a id="d0e21280" class="indexterm"></a><a id="d0e21285" class="indexterm"></a>
				<p>
					Similar to the <code class="literal">every</code> operator in most aspects, the <code class="literal">every-distinct</code> operator indicates that the pattern sub-expression should restart when the subexpression qualified by the <code class="literal">every-distinct</code> keyword evaluates to true or false. In addition, the <code class="literal">every-distinct</code> eliminates duplicate results received from an active subexpression according to its distinct-value expressions.
				</p>
				<p>
					The synopsis for the <code class="literal">every-distinct</code> pattern operator is:
				</p>
				<pre class="synopsis">every-distinct(<span class="emphasis"><em>distinct_value_expr </em></span>[, <span class="emphasis"><em>distinct_value_exp</em></span>[...][, <span class="emphasis"><em>expiry_time_period</em></span>])</pre>
				<p>
					Within parenthesis are one or more <span class="emphasis"><em>distinct_value_expr</em></span> expressions that return the values by which to remove duplicates.
					Further detail on key expressions can be found at <a class="xref" href="epl_clauses.html#epl-syntax-compositekey" title="5.2.13. Composite Keys and Array Values as Keys">Section 5.2.13, “Composite Keys and Array Values as Keys”</a>.
				</p>
				<p>
					You may optionally specify an <span class="emphasis"><em>expiry_time_period</em></span> time period. If present, the pattern runtime expires and removes distinct key values that are older then the time period, removing their associated memory and allowing such distinct values to match again.
					When your distinct value expressions return an unlimited number of values, for example when your distinct value is a timestamp or auto-increment column, you should always specify an expiry time period.
				</p>
				<p>
					When specifying properties in the distinct-value expression list, you must ensure that the event types providing properties are tagged. Only properties of event types within filter expressions that are sub-expressions to the <code class="literal">every-distinct</code> may be specified.
				</p>
				<p>
					For example, this pattern keeps firing for every A event with a distinct value for its <code class="literal">aprop</code> property:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every-distinct(a.aprop) a=A</pre>
				<p>
					Note that the pattern above assigns the <code class="literal">a</code> tag to the A event and uses <code class="literal">a.prop</code> to identify the <code class="literal">prop</code> property as a value of the <code class="literal">a</code> event A.
				</p>
				<p>
					A pattern that returns the first Sample event for each sensor, assuming sensor is a field that returns a unique id identifying the sensor that originated the Sample event, is:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every-distinct(s.sensor) s=Sample</pre>
				<p>
					The next pattern looks for pairs of A and B events and returns only the first pair for each combination of <code class="literal">aprop</code> of an A event and <code class="literal">bprop</code> of a B event:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every-distinct(a.aprop, b.bprop) (a=A and b=B)</pre>
				<p>
					The following pattern looks for A events followed by B events for which the value of the <code class="literal">aprop</code> of an A event is the same value of the <code class="literal">bprop</code> of a B event but only for each distinct value of <code class="literal">aprop</code> of an A event:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every-distinct(a.aprop) a=A -&gt; b=B(bprop = a.aprop)</pre>
				<p>
					When specifying properties as part of distinct-value expressions, properties must be available from tagged event types in sub-expressions to the <code class="literal">every-distinct</code>.
				</p>
				<p>
					The following patterns are not valid:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">// Invalid: event type in filter not tagged
every-distinct(aprop) A
			
// Invalid: property not from a sub-expression of every-distinct
a=A -&gt; every-distinct(a.aprop) b=B</pre>
				<p>
					When an active subexpression to <code class="literal">every-distinct</code> becomes permanently false, the distinct-values seen from the active subexpression are removed and the sub-expression within is restarted.
				</p>
				<p>
					For example, the below pattern detects each A event distinct by the value of <code class="literal">aprop</code>.
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every-distinct(a.aprop) (a=A and not B)</pre>
				<p>
					In the pattern above, when a B event arrives, the subexpression becomes permanently false and is restarted anew, detecting each A event distinct by the value of <code class="literal">aprop</code> without considering prior values.
				</p>
				<p>
					When your distinct key is a timestamp or other non-unique property, specify an expiry time period.
				</p>
				<p>
					The following example returns every distinct A event according to the timestamp property on the A event, retaining each timestamp value for 10 seconds:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every-distinct(a.timestamp, 10 seconds) a=A</pre>
				<p>
					In the example above, if for a given A event and its timestamp value the same timestamp value occurs again for another A event before 10 seconds passed, the A event is not a match. If 10 seconds passed the pattern indicates a second match.
				</p>
				<p>
					You may not use every-distinct with a timer-within guard to expire keys: The expiry time notation as above is the recommended means to expire keys.
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">// This is not the same as above; It does not expire transaction ids and is not recommended
every-distinct(a.timestamp) a=A where timer:within(10 sec)</pre>
			</div>
			<div class="sect2" lang="en-US">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title"><a id="pattern-repeat"></a>7.5.3. Repeat</h3>
						</div>
					</div>
				</div>
				<p>
					The repeat operator fires when a pattern sub-expression evaluates to true a given number of times. The synopsis is as follows:
				</p>
				<pre class="synopsis">[<span class="emphasis"><em>match_count</em></span>] <span class="emphasis"><em>repeating_subexpr</em></span></pre>
				<p>
					The repeat operator is very similar to the <code class="literal">every</code> operator in that it restarts the <span class="emphasis"><em>repeating_subexpr</em></span> pattern sub-expression up to a given number of times.
				</p>
				<p>
					<span class="emphasis"><em>match_count</em></span> is a positive number that specifies how often the <span class="emphasis"><em>repeating_subexpr</em></span> pattern sub-expression must evaluate to true before the repeat expression itself evaluates to true, after which the runtime may indicate a match.
				</p>
				<p>
					For example, this pattern fires when the last of five A events arrives:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">[5] A</pre>
				<p>
					Parenthesis must be used for nested pattern sub-expressions. This pattern fires when the last of a total of any five A or B events arrives:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">[5] (A or B)</pre>
				<p>
					Without parenthesis the pattern semantics change, according to the operator precedence described earlier. This pattern fires when the last of a total of five A events arrives or a single B event arrives, whichever happens first:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">[5] A or B</pre>
				<p>
					Tags can be used to name events in filter expression of pattern sub-expressions. The next pattern looks for an A event followed by a B event, and a second A event followed by a second B event. The output event provides indexed and array properties of the same name:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">[2] (a=A -&gt; b=B)</pre>
				<p>
					Using tags with repeat is further described in <a class="xref" href="event_patterns.html#pattern-repeat-tags" title="7.5.4.6. Tags and the Repeat Operator">Section 7.5.4.6, “Tags and the Repeat Operator”</a>.
				</p>
				<p>
					Consider the following pattern that demonstrates the behavior when a pattern sub-expression becomes permanently false:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">[2] (a=A and not C)</pre>
				<p>
					In the case where a C event arrives before 2 A events arrive, the pattern above becomes permanently false.
				</p>
				<p>
					Lets add an <code class="literal">every</code> operator to restart the pattern and thus keep matching for all pairs of A events that arrive without a C event in between each pair:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every [2] (a=A and not C)</pre>
				<p>
					Since pattern matches return multiple A events, your select clause should use tag <code class="literal">a</code> as an array, for example:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">select a[0].id, a[1].id from pattern [every [2] (a=A and not C)]</pre>
			</div>
			<div class="sect2" lang="en-US">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title"><a id="pattern-repeatuntil"></a>7.5.4. Repeat-Until</h3>
						</div>
					</div>
				</div>
				<p>
					The repeat <code class="literal">until</code> operator provides additional control over repeated matching.
				</p>
				<p>
					The repeat until operator takes an optional range, a pattern sub-expression to repeat, the <code class="literal">until</code> keyword and a second pattern sub-expression that ends the repetition. The synopsis is as follows:
				</p>
				<pre class="synopsis">[<span class="emphasis"><em>range</em></span>] <span class="emphasis"><em>repeated_pattern_expr</em></span> until <span class="emphasis"><em>end_pattern_expr</em></span></pre>
				<p>
					Without a <span class="emphasis"><em>range</em></span>, the runtime matches the <span class="emphasis"><em>repeated_pattern_expr</em></span> pattern sub-expression until the <span class="emphasis"><em>end_pattern_expr</em></span> evaluates to true, at which time the expression turns true.
				</p>
				<p>
					An optional <span class="emphasis"><em>range</em></span> can be used to indicate the minimum number of times that the <span class="emphasis"><em>repeated_pattern_expr</em></span> pattern sub-expression must become true.
				</p>
				<p>
					The optional <span class="emphasis"><em>range</em></span> can also specify a maximum number of times that <span class="emphasis"><em>repeated_pattern_expr</em></span> pattern sub-expression evaluates to true and retains tagged events. When this number is reached, the runtime stops the <span class="emphasis"><em>repeated_pattern_expr</em></span> pattern sub-expression.
				</p>
				<p>
					The <code class="literal">until</code> keyword is always required when specifying a range and is not required if specifying a fixed number of repeat as discussed in the section before.
				</p>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-repeatuntil-norange"></a>7.5.4.1. Unbound Repeat</h4>
							</div>
						</div>
					</div>
					<p>
						In the unbound repeat, without a <span class="emphasis"><em>range</em></span>, the runtime matches the <span class="emphasis"><em>repeated_pattern_expr</em></span> pattern sub-expression until the <span class="emphasis"><em>end_pattern_expr</em></span> evaluates to true, at which time the expression turns true. The synopsis is:
					</p>
					<pre class="synopsis"><span class="emphasis"><em>repeated_pattern_expr</em></span> until <span class="emphasis"><em>end_pattern_expr</em></span></pre>
					<p>
						This is a pattern that keeps looking for A events until a B event arrives:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">A until B</pre>
					<p>
						Nested pattern sub-expressions must be placed in parenthesis since the <code class="literal">until</code> operator has precedence over most operators. This example collects all A or B events for 10 seconds and places events received in indexed properties 'a' and 'b':
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">(a=A or b=B) until timer:interval(10 sec)</pre>
				</div>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-repeatuntil-range"></a>7.5.4.2. Bound Repeat Overview</h4>
							</div>
						</div>
					</div>
					<p>
						The synopsis for the optional <span class="emphasis"><em>range</em></span> qualifier is:
					</p>
					<pre class="synopsis">[ [<span class="emphasis"><em>low_endpoint</em></span>] : [<span class="emphasis"><em>high_endpoint</em></span>] ]</pre>
					<p>
						<span class="emphasis"><em>low_endpoint</em></span> is an optional number that appears on the left of a colon (:), after which follows an optional <span class="emphasis"><em>high_endpoint</em></span> number.
					</p>
					<p>
						A range thus consists of a <span class="emphasis"><em>low_endpoint</em></span> and a <span class="emphasis"><em>high_endpoint</em></span> in square brackets and separated by a colon (:) characters. Both endpoint values are optional but either one or both must be supplied. The <span class="emphasis"><em>low_endpoint</em></span> can be omitted to denote a range that starts at zero. The <span class="emphasis"><em>high_endpoint</em></span> can be omitted to denote an open-ended range.
					</p>
					<p>
						Some examples for valid ranges might be:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">[3 : 10]
[:3]    // range starts at zero
[2:]    // open-ended range</pre>
					<p>
						The <span class="emphasis"><em>low_endpoint</em></span>, if specified, defines the minimum number of times that the <span class="emphasis"><em>repeated_pattern_expr</em></span> pattern sub-expression must become true in order for the expression to become true.
					</p>
					<p>
						The <span class="emphasis"><em>high_endpoint</em></span>, if specified, is the maximum number of times that the <span class="emphasis"><em>repeated_pattern_expr</em></span> pattern sub-expression becomes true. If the number is reached, the runtime stops the <span class="emphasis"><em>repeated_pattern_expr</em></span> pattern sub-expression.
					</p>
					<p>
						In all cases, only at the time that the <span class="emphasis"><em>end_pattern_expr</em></span> pattern sub-expression evaluates to true does the expression become true. If <span class="emphasis"><em>end_pattern_expr</em></span> pattern sub-expression evaluates to false, then the expression evaluates to false.
					</p>
				</div>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-repeatuntil-range-openended"></a>7.5.4.3. Bound Repeat - Open Ended Range</h4>
							</div>
						</div>
					</div>
					<p>
						An open-ended range specifies only a low endpoint and not a high endpoint.
					</p>
					<p>
						Consider the following pattern which requires at least three A events to match:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">[3:] A until B</pre>
					<p>
						In the pattern above, if a B event arrives before 3 A events occurred, the expression ends and evaluates to false.
					</p>
				</div>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-repeatuntil-range-nolow"></a>7.5.4.4. Bound Repeat - High Endpoint Range</h4>
							</div>
						</div>
					</div>
					<p>
						A high-endpoint range specifies only a high endpoint and not a low endpoint.
					</p>
					<p>
						In this sample pattern the runtime will be looking for a maximum of 3 A events. The expression turns true as soon as a single B event arrives regardless of the number of A events received:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">[:3] A until B</pre>
					<p>
						The next pattern matches when a C or D event arrives, regardless of the number of A or B events that occurred:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">[:3] (a=A or b=B) until (c=C or d=D)</pre>
					<p>
						In the pattern above, if more then 3 A or B events arrive, the pattern stops looking for additional A or B events. The 'a' and 'b' tags retain only the first 3 (combined) matches among A and B events. The output event contains these tagged events as indexed properties.
					</p>
				</div>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-repeatuntil-range-bounded"></a>7.5.4.5. Bound Repeat - Bounded Range</h4>
							</div>
						</div>
					</div>
					<p>
						A bounded range specifies a low endpoint and a high endpoint.
					</p>
					<p>
						The next pattern matches after at least one A event arrives upon the arrival of a single B event:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">[1:3] a=A until B</pre>
					<p>
						If a B event arrives before the first A event, then the pattern does not match. Only the first 3 A events are returned by the pattern.
					</p>
				</div>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-repeat-tags"></a>7.5.4.6. Tags and the Repeat Operator</h4>
							</div>
						</div>
					</div>
					<p>
						The tags assigned to events in filter subexpressions within a repeat operator are available for use in filter expressions and also in any EPL clause.
					</p>
					<p>
						This sample pattern matches 2 A events followed by a B event. Note the filter on B events: only a B event that has a value for the "beta" property that equals any of the "id" property values of the two A events is considered:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">[2] A -&gt; B(beta in (a[0].id, a[1].id))</pre>
					<p>
						The next statement returns pairs of A events:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">select a, a[0], a[0].id, a[1], a[1].id
from pattern [ every [2] a=A ] </pre>
					<p>
						The <code class="literal">select</code> clause of the statement above showcases different ways of accessing tagged events:
					</p>
					<div class="itemizedlist">
						<ul>
							<li>
								<p>
									The tag itself can be used to select an array of underlying events. For example, the 'a' expression above returns an array of underlying events of event type A.
								</p>
							</li>
							<li>
								<p>
									The tag as an indexed property returns the underlying event at that index. For instance, the 'a[0]' expression returns the first underlying A event, or null if no such A event was matched by the repeat operator.
								</p>
							</li>
							<li>
								<p>
									The tag as a nested, indexed property returns a property of the underlying event at that index. For example, the 'a[1].id' expression returns the 'id' property value of the second A event, or null if no such second A event was matched by the repeat operator.
								</p>
							</li>
						</ul>
					</div>
				</div>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-repeatuntil-index"></a>7.5.4.7. Note on Indexed Tags</h4>
							</div>
						</div>
					</div>
					<p>
						You may not use indexed tags defined in the sub-expression to the repeat operator in the same subexpression. For example, in the following pattern the subexpression to the repeat operator is <code class="literal">(a=A() -&gt; b=B(id=a[0].id))</code> and the tag <code class="literal">a</code> cannot be used in its indexed form in the filter for event B:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">// invalid
every [2] (a=A() -&gt; b=B(id=a[0].id))</pre>
					<p>
						You can use tags without an index:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">// valid
every [2] (a=A() -&gt; b=B(id=a.id))</pre>
				</div>
			</div>
			<div class="sect2" lang="en-US">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title"><a id="pattern-logical-and"></a>7.5.5. And</h3>
						</div>
					</div>
				</div><a id="d0e21734" class="indexterm"></a><a id="d0e21739" class="indexterm"></a>
				<p>
					Similar to the Java &amp;&amp; operator the <code class="literal">and</code> operator requires both nested pattern expressions to turn
					true before the whole expression turns true (a join pattern).
				</p>
				<p>
					This pattern matches when both an A event and a B event arrive, at the time the last of the two events arrive:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">A and B</pre>
				<p>
					This pattern matches on any sequence of an A event followed by a B event and then a C event followed by a D event, or a C event followed by a D and an A event followed by a B event:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">(A -&gt; B) and (C -&gt; D)</pre>
				<p>
					Note that in an <code class="literal">and</code> pattern expression it is not possible to correlate events based on event property values. For example, this is an invalid pattern:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">// This is NOT valid
a=A and B(id = a.id)</pre>
				<p>
					The above expression is invalid as it relies on the order of arrival of events, however in an <code class="literal">and</code> expression the order of events is not specified and events fulfill an <code class="literal">and</code> condition in any order. The above expression can be changed to use the followed-by operator:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">// This is valid
a=A -&gt; B(id = a.id)
// another example using 'and'...
a=A -&gt; (B(id = a.id) and C(id = a.id))</pre>
				<p>
					Consider a pattern that looks for the same event:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">A and A</pre>
				<p>
					The pattern above fires when a single A event arrives. The first arriving A event triggers a state transition in both the left and the right hand side expression.
				</p>
				<p>
					In order to match after two A events arrive in any order, there are two options to express this pattern. The followed-by operator is one option and the repeat operator is the second option, as the next two patterns show:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">A -&gt; A
// ... or ...
[2] A</pre>
			</div>
			<div class="sect2" lang="en-US">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title"><a id="pattern-logical-or"></a>7.5.6. Or</h3>
						</div>
					</div>
				</div><a id="d0e21787" class="indexterm"></a><a id="d0e21792" class="indexterm"></a>
				<p>
					Similar to the Java “||” operator the <code class="literal">or</code> operator requires either one of the expressions
					to turn true before the whole expression turns true.
				</p>
				<p>
					Look for either an A event or a B event. As always, A and B can itself be nested expressions as well.
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">A or B</pre>
				<p>
					The next EPL outputs all A and B events:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every A or every B</pre>
				<p>
					Elaborating further, the expression <code class="literal">every A or every B</code> is equivalent to <code class="literal">every (A or B)</code>.
					Prefer <code class="literal">every A or every B</code> as the <code class="literal">every</code> keyword lets the runtime know that filters for A and B can remain active.
					Consider the expression <code class="literal">every A or every timer:interval(10 sec)</code> which is not equivalent to <code class="literal">every (A or timer:interval(10 sec))</code>.
					This is because in the latter expression when an A event arrives the interval restarts.
				</p>
			</div>
			<div class="sect2" lang="en-US">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title"><a id="pattern-logical-not"></a>7.5.7. Not</h3>
						</div>
					</div>
				</div><a id="d0e21833" class="indexterm"></a><a id="d0e21838" class="indexterm"></a>
				<p>
					The <code class="literal">not</code> operator negates the truth value of an expression. Pattern expressions prefixed with <code class="literal">not</code> are automatically
					defaulted to true upon start, and turn permanently false when the expression within turns true.
				</p>
				<p>
					The <code class="literal">not</code> operator is generally used in conjunction with the <code class="literal">and</code> operator or subexpressions as the below examples show.
				</p>
				<p>
					This pattern matches only when an A event is encountered followed by a B event but only if no C event was encountered before either an A event and a B event, counting from the time the pattern is started:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">(A -&gt; B) and not C</pre>
				<p>
					Assume we'd like to detect when an A event is followed by a D event, without any B or C events between the A and D events:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">A -&gt; (D and not (B or C))</pre>
				<p>
					It may help your understanding to discuss a pattern that uses the <code class="literal">or</code> operator and the <code class="literal">not</code> operator together:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">a=A -&gt; (b=B or not C)</pre>
				<p>
					In the pattern above, when an A event arrives then the runtime starts the subexpression <code class="literal">B or not C</code>. As soon as the subexpression starts, the <code class="literal">not</code> operator turns to true. The <code class="literal">or</code> expression turns true and thus your listener receives an invocation providing the A event in the property 'a'. The subexpression does not end and continues listening for B and C events. Upon arrival of a B event your listener receives a second invocation. If instead a C event arrives, the <code class="literal">not</code> turns permanently false however that does not affect the <code class="literal">or</code> operator (but would end an <code class="literal">and</code> operator).
				</p>
				<p>
					To test for absence of an event, use <code class="literal">timer:interval</code> together with <code class="literal">and not</code> operators. The sample statement reports each 10-second interval during which no A event occurred:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every (timer:interval(10 sec) and not A)</pre>
				<p>
					In many cases the <code class="literal">not</code> operator, when used alone, does not make sense. The following example is invalid and will log a warning when the runtime is started:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">// not a sensible pattern
(not a=A) -&gt; B(id=a.id)</pre>
			</div>
			<div class="sect2" lang="en-US">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title"><a id="pattern-temporal-followed-by"></a>7.5.8. Followed-By</h3>
						</div>
					</div>
				</div><a id="d0e21917" class="indexterm"></a><a id="d0e21922" class="indexterm"></a><a id="d0e21927" class="indexterm"></a>
				<p>
					The followed by <code class="literal">-&gt;</code> operator specifies that first the left hand expression must turn true and only
					then is the right hand expression evaluated for matching events.
				</p>
				<p>
					Look for an A event and if encountered, look for a B event. As always, A and B can itself be nested event pattern expressions.
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">A -&gt; B</pre>
				<p>
					This is a pattern that fires when 2 status events indicating an error occur one after the other.
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">StatusEvent(status='ERROR') -&gt; StatusEvent(status='ERROR')</pre>
				<p>
					A pattern that takes all A events that are not followed by a B event within 5 minutes:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every A -&gt; (timer:interval(5 min) and not B)</pre>
				<p>
					A pattern that takes all A events that are not preceded by B within 5 minutes:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every (timer:interval(5 min) and not B -&gt; A)</pre>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-temporal-followed-by-max"></a>7.5.8.1. Limiting Sub-Expression Count</h4>
							</div>
						</div>
					</div>
					<p>
						The followed-by <code class="literal">-&gt;</code> operator can optionally be provided with an expression that limits the number of sub-expression instances of the right-hand side pattern sub-expression.
					</p>
					<p>
						The synopsis for the followed-by operator with limiting expression is:
					</p>
					<pre class="synopsis"><span class="emphasis"><em>lhs_expression</em></span> -[<span class="emphasis"><em>limit_expression</em></span>]&gt; <span class="emphasis"><em>rhs_expression</em></span></pre>
					<p>
						Each time the <span class="emphasis"><em>lhs_expression</em></span> pattern sub-expression turns true the pattern runtime starts a new <span class="emphasis"><em>rhs_expression</em></span> pattern sub-expression.
						The <span class="emphasis"><em>limit_expression</em></span> returns an integer value that defines a maximum number of pattern sub-expression instances that can simultaneously be present for the same <span class="emphasis"><em>rhs_expression</em></span>.
					</p>
					<p>
						When the limit is reached the pattern runtime issues a <code class="literal">com.espertech.esper.common.client.hook.condition.ConditionPatternSubexpressionMax</code> notification object to any condition handlers registered with the runtime as described in <a class="xref" href="apiruntime.html#apiruntime-condition" title="16.11. Condition Handling">Section 16.11, “Condition Handling”</a> and does not start a new pattern sub-expression instance for the right-hand side pattern sub-expression.
					</p>
					<p>
						For example, consider the following pattern which returns for every A event the first B event that matches the <code class="literal">id</code> field value of the A event:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every a=A -&gt; b=B(id = a.id)</pre>
					<p>
						In the above pattern, every time an A event arrives (lhs) the pattern runtime starts a new pattern sub-expression (rhs) consisting of a filter for the first B event that has the same value for the <code class="literal">id</code> field as the A event.
					</p>
					<p>
						In some cases your application may want to limit the number of right-hand side sub-expressions because of memory concerns or to reduce output. You may add a limit expression returning an integer value
						as part of the operator.
					</p>
					<p>
						This example employs the followed-by operator with a limit expression to indicate that maximally 2 filters for B events (the right-hand side pattern sub-expression) may be active at the same time:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every a=A -[2]&gt; b=B(id = a.id)</pre>
					<p>
						Note that the limit expression in the example above is not a limit per value of <code class="literal">id</code> field, but a limit counting all right-hand side pattern sub-expression instances that are managed by that followed-by sub-expression instance.
					</p>
					<p>
						If your followed-by operator lists multiple sub-expressions with limits, each limit applies to the immediate right-hand side. For example, the pattern below limits the number of filters for B events to 2 and the number of filters for C events to 3:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every a=A -[2]&gt; b=B(id = a.id) -[3]&gt; c=C(id = a.id)</pre>
				</div>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-temporal-followed-by-runtime-max"></a>7.5.8.2. Limiting Runtime-Wide Sub-Expression Count</h4>
							</div>
						</div>
					</div>
					<p>
						The runtime allows setting a maximum number of pattern sub-expressions in the configuration, applicable to all followed-by operators of all statements.
					</p>
					<p>
						If your application has patterns in multiple statements and all such patterns should count towards a total number of pattern sub-expression counts, you may consider setting a maximum number of pattern sub-expression instances, runtime-wide, via the
						configuration described in <a class="xref" href="configuration.html#configuration-runtime-patterns-max" title="17.6.4.1. Followed-By Operator Maximum Subexpression Count">Section 17.6.4.1, “Followed-By Operator Maximum Subexpression Count”</a>.
					</p>
					<p>
						When the limit is reached the pattern runtime issues a notification object to any condition handlers registered with the runtime as described in <a class="xref" href="apiruntime.html#apiruntime-condition" title="16.11. Condition Handling">Section 16.11, “Condition Handling”</a>. Depending on your configuration the runtime can prevent the start of a new pattern sub-expression instance for the right-hand side pattern sub-expression, until pattern sub-expression instances end or statements are undeployed.
					</p>
					<p>
						The notification object issued to condition handlers is an instance of <code class="literal">com.espertech.esper.common.client.hook.condition.ConditionPatternRuntimeSubexpressionMax</code>. The notification object contains information which statement triggered the limit and the pattern counts per statement for all statements.
					</p>
					<p>
						For information on configuration please consult <a class="xref" href="configuration.html#configuration-runtime-patterns-max" title="17.6.4.1. Followed-By Operator Maximum Subexpression Count">Section 17.6.4.1, “Followed-By Operator Maximum Subexpression Count”</a>.
					</p>
				</div>
			</div>
			<div class="sect2" lang="en-US">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title"><a id="pattern-guards"></a>7.5.9. Pattern Guards</h3>
						</div>
					</div>
				</div><a id="d0e22045" class="indexterm"></a>
				<p>
					Guards are where-conditions that control the lifecycle of subexpressions. Custom guard functions can also be used. The section <a class="xref" href="extension.html" title="Chapter 22. Integration and Extension">Chapter 22, <i>Integration and Extension</i></a> outlines guard plug-in development in greater detail.
				</p>
				<p>
					The pattern guard where-condition has no relationship to the EPL <code class="literal">where</code> clause that filters sets of events.
				</p>
				<p>
					Take as an example the following pattern expression:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">MyEvent where timer:within(10 sec)</pre>
				<p>
					In this pattern the <code class="literal">timer:within</code> guard controls the subexpression that is looking for MyEvent events. The guard terminates the subexpression looking for MyEvent events after 10 seconds after start of the pattern. Thus the pattern alerts only once when the first MyEvent event arrives within 10 seconds after start of the pattern.
				</p>
				<p>
					The <code class="literal">every</code> keyword requires additional discussion since it also controls subexpression lifecycle. Let's add the <code class="literal">every</code> keyword to the example pattern:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every MyEvent where timer:within(10 sec)</pre>
				<p>
					The difference to the pattern without <code class="literal">every</code> is that each MyEvent event that arrives now starts a new subexpression, including a new guard, looking for a further MyEvent event. The result is that, when a MyEvent arrives within 10 seconds after pattern start, the pattern execution will look for the next MyEvent event to arrive within 10 seconds after the previous one.
				</p>
				<p>
					By placing parentheses around the <code class="literal">every</code> keyword and its subexpression, you can have the <code class="literal">every</code> under the control of the guard:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">(every MyEvent) where timer:within(10 sec)</pre>
				<p>
					In the pattern above, the guard terminates the subexpression looking for all MyEvent events after 10 seconds after start of the pattern. This pattern alerts for all MyEvent events arriving within 10 seconds after pattern start, and then stops.
				</p>
				<p>
					Guards do not change the truth value of the subexpression of which the guard controls the lifecycle, and therefore do not cause a restart of the subexpression when used with the <code class="literal">every</code> operator. For example, the next pattern stops returning matches after 10 seconds unless a match occurred within 10 seconds after pattern start:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every ( (A and B) where timer:within(10 sec) )</pre>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-guards-timerwithin"></a>7.5.9.1. The <code class="literal">timer:within</code> Pattern Guard</h4>
							</div>
						</div>
					</div><a id="d0e22106" class="indexterm"></a><a id="d0e22111" class="indexterm"></a>
					<p>
						The <code class="literal">timer:within</code> guard acts like a stopwatch.
						If the associated pattern expression does not turn true within the specified time period it is stopped and permanently false.
					</p>
					<p>
						The synopsis for <code class="literal">timer:within</code> is as follows:
					</p>
					<pre class="synopsis">timer:within(<span class="emphasis"><em>time_period_expression</em></span>)</pre>
					<p>
						The <span class="emphasis"><em>time_period_expression</em></span> is a time period (see <a class="xref" href="epl_clauses.html#epl-syntax-time-periods" title="5.2.1. Specifying Time Periods">Section 5.2.1, “Specifying Time Periods”</a>) or an expression providing a number of seconds as a parameter. The interval expression may
						contain references to properties of prior events in the same pattern as well as variables and substitution parameters.
					</p>
					<p>
						This pattern fires if an A event arrives within 5 seconds after statement deployment.
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">A where timer:within (5 seconds)</pre>
					<p>
						This pattern fires for all A events that arrive within 5 seconds. After 5 seconds, this pattern stops matching even if more A events arrive.
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">(every A) where timer:within (5 seconds)</pre>
					<p>
						This pattern matches for any one A or B event in the next 5 seconds.
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">( A or B ) where timer:within (5 sec)</pre>
					<p>
						This pattern matches for any 2 errors that happen 10 seconds within each other.
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every (StatusEvent(status='ERROR') -&gt; StatusEvent(status='ERROR') where timer:within (10 sec))</pre>
					<p>
						The following guards are equivalent:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">timer:within(2 minutes 5 seconds)
timer:within(125 sec)
timer:within(125)</pre>
				</div>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-guards-timerwithinmax"></a>7.5.9.2. The <code class="literal">timer:withinmax</code> Pattern Guard</h4>
							</div>
						</div>
					</div><a id="d0e22164" class="indexterm"></a><a id="d0e22169" class="indexterm"></a>
					<p>
						The <code class="literal">timer:withinmax</code> guard is similar to the <code class="literal">timer:within</code> guard and acts as a stopwatch that additionally has a counter that counts the number of matches. It ends the subexpression when either the stopwatch ends or the match counter maximum value is reached.
					</p>
					<p>
						The synopsis for <code class="literal">timer:withinmax</code> is as follows:
					</p>
					<pre class="synopsis">timer:withinmax(<span class="emphasis"><em>time_period_expression</em></span>, <span class="emphasis"><em>max_count_expression</em></span>)</pre>
					<p>
						The <span class="emphasis"><em>time_period_expression</em></span> is a time period (see <a class="xref" href="epl_clauses.html#epl-syntax-time-periods" title="5.2.1. Specifying Time Periods">Section 5.2.1, “Specifying Time Periods”</a>) or an expression providing a number of seconds.
					</p>
					<p>
						The <span class="emphasis"><em>max_count_expression</em></span> provides the maximum number of matches before the guard ends the subexpression.
					</p>
					<p>
						Each parameter expression may also contain references to properties of prior events in the same pattern as well as variables and substitution parameters.
					</p>
					<p>
						This pattern fires for every A event that arrives within 5 seconds after statement deployment but only up to the first two A events:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">(every A) where timer:withinmax (5 seconds, 2)</pre>
					<p>
						If the result of the <span class="emphasis"><em>max_count_expression</em></span> is 1, the guard ends the subexpression after the first match and indicates the first match.
					</p>
					<p>
						This pattern fires for the first A event that arrives within 5 seconds after statement deployment:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">(every A) where timer:withinmax (5 seconds, 1)</pre>
					<p>
						If the result of the <span class="emphasis"><em>max_count_expression</em></span> is zero, the guard ends the subexpression upon the first match and does no indicate any matches.
					</p>
					<p>
						This example receives every A event followed by every B event (as each B event arrives) until the 5-second subexpression timer ends or X number of B events have arrived (assume X was declared as a variable):
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every A -&gt; (every B) where timer:withinmax (5 seconds, X)</pre>
				</div>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-guards-while"></a>7.5.9.3. The <code class="literal">while</code> Pattern Guard</h4>
							</div>
						</div>
					</div><a id="d0e22237" class="indexterm"></a><a id="d0e22242" class="indexterm"></a>
					<p>
						The <code class="literal">while</code> guard is followed by an expression that the runtime evaluates for every match reported by the guard pattern sub-expression. When the expression returns false the pattern sub-expression ends.
					</p>
					<p>
						The synopsis for <code class="literal">while</code> is as follows:
					</p>
					<pre class="synopsis">while (<span class="emphasis"><em>guard_expression</em></span>)</pre>
					<p>
						The <span class="emphasis"><em>guard_expression</em></span> is any expression that returns a boolean true or false. The expression may contain references to properties of prior events in the same pattern as well as variables and substitution parameters.
					</p>
					<p>
						Each time the subexpression indicates a match, the runtime evaluates <span class="emphasis"><em>guard_expression</em></span> and if true, passes the match and when false, ends the subexpression.
					</p>
					<p>
						This pattern fires for every A event until an A event arrives that has a value of zero or less for its <code class="literal">size</code> property (assuming A events have an integer <code class="literal">size</code> property).
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">(every a=A) while (a.size &gt; 0)</pre>
					<p>
						Note the parenthesis around the <code class="literal">every</code> subexpression. They ensure that, following precedence rules, the guard applies to the <code class="literal">every</code> operator as well.
					</p>
				</div>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-guards-timeparameters"></a>7.5.9.4. Guard Time Interval Expressions</h4>
							</div>
						</div>
					</div>
					<p>
						The <code class="literal">timer:within</code> and <code class="literal">timer:withinmax</code> guards may be parameterized by an expression that contains one or more references to properties of prior events in the same pattern.
					</p>
					<p>
						As a simple example, this pattern matches every A event followed by a B event that arrives within <code class="literal">delta</code> seconds after the A event:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every a=A -&gt; b=B where timer:within (a.delta seconds)</pre>
					<p>
						Herein A event is assumed to have a <code class="literal">delta</code> property that provides the number of seconds to wait for B events. Each arriving A event may have a different value for <code class="literal">delta</code>
						and the guard is therefore parameterized dynamically based on the prior A event received.
					</p>
					<p>
						When multiple events accumulate, for example when using the match-until or repeat pattern elements, an index must be provided:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">[2] a=A -&gt; b=B where timer:within (a[0].delta + a[1].delta)</pre>
					<p>
						The above pattern matches after 2 A events arrive followed by a B event within a time interval after the A event that is defined by the sum of the <code class="literal">delta</code> properties of both A events.
					</p>
				</div>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-guards-combining"></a>7.5.9.5. Combining Guard Expressions</h4>
							</div>
						</div>
					</div>
					<p>
						You can combine guard expression by using parenthesis around each subexpression.
					</p>
					<p>
						The below pattern matches for each A event while A events of size greater then zero arrive and only within the first 20 seconds:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">((every a=A) while (a.size &gt; 0)) where timer:within(20)</pre>
				</div>
			</div>
		</div>
		<div class="sect1" lang="en-US">
			<div class="titlepage">
				<div>
					<div>
						<h2 class="title"><a id="pattern-atoms"></a>7.6. Pattern Atoms</h2>
					</div>
				</div>
			</div><a id="d0e22337" class="indexterm"></a>
			<div class="sect2" lang="en-US">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title"><a id="pattern-atom-filter"></a>7.6.1. Filter Atoms</h3>
						</div>
					</div>
				</div>
				<p>
					Filter atoms have been described in section <a class="xref" href="event_patterns.html#pattern-filter" title="7.4. Filter Expressions in Patterns">Section 7.4, “Filter Expressions in Patterns”</a>.
				</p>
			</div>
			<div class="sect2" lang="en-US">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title"><a id="pattern-atom-time"></a>7.6.2. Observer Atoms Overview</h3>
						</div>
					</div>
				</div>
				<p>
					Observers observe time-based events for which the thread-of-control originates by the runtime timer or external timer event.
					Custom observers can also be developed that observe timer events or other runtime-external application events such as a file-exists check.
					The section <a class="xref" href="extension.html" title="Chapter 22. Integration and Extension">Chapter 22, <i>Integration and Extension</i></a> outlines observer plug-in development in greater detail.
				</p>
			</div>
			<div class="sect2" lang="en-US">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title"><a id="pattern-timer-interval"></a>7.6.3. Interval (<code class="literal">timer:interval</code>)</h3>
						</div>
					</div>
				</div><a id="d0e22360" class="indexterm"></a><a id="d0e22365" class="indexterm"></a>
				<p>
					The <code class="literal">timer:interval</code> pattern observer waits for the defined time before the truth value of the observer turns true.
					The observer takes a time period (see <a class="xref" href="epl_clauses.html#epl-syntax-time-periods" title="5.2.1. Specifying Time Periods">Section 5.2.1, “Specifying Time Periods”</a>) as a parameter, or an expression that returns the number of seconds.
				</p>
				<p>
					The observer may be parameterized by an expression that contains one or more references to properties of prior events in the same pattern, or may also reference variables, substitution parameters or any other expression returning
					a numeric value.
				</p>
				<p>
					After an A event arrived wait 10 seconds then indicate that the pattern matches.
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">A -&gt; timer:interval(10 seconds) </pre>
				<p>
					The pattern below fires every 20 seconds.
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every timer:interval(20 sec)</pre>
				<p>
					The next example pattern fires for every A event that is not followed by a B event within 60 seconds after the A event arrived. The B event must have the same "id" property
					value as the A event.
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every a=A -&gt; (timer:interval(60 sec) and not B(id=a.id)) </pre>
				<p>
					Consider the next example, which assumes that the A event has a property <code class="literal">waittime</code>:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every a=A -&gt; (timer:interval(a.waittime + 2) and not B(id=a.id))</pre>
				<p>
					In the above pattern the logic waits for 2 seconds plus the number of seconds provided by the value of the <code class="literal">waittime</code> property of the A event.
				</p>
			</div>
			<div class="sect2" lang="en-US">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title"><a id="pattern-timer-at"></a>7.6.4. Crontab (<code class="literal">timer:at</code>)</h3>
						</div>
					</div>
				</div><a id="d0e22409" class="indexterm"></a><a id="d0e22414" class="indexterm"></a>
				<p>
					The <code class="literal">timer:at</code> pattern observer is similar in function to the Unix “crontab” command. At a specified time the
					expression turns true. The <code class="literal">at</code> operator can also be made to pattern match at regular intervals by using an <code class="literal">every</code> operator
					in front of the <code class="literal">timer:at</code> operator.
				</p>
				<p>
					The syntax is:
				</p>
				<pre class="synopsis">timer:at (minutes, hours, days of month, months, days of week [, seconds [, time zone [, milliseconds [, microseconds]]]])</pre>
				<p>
					The value for seconds, time zone, milliseconds and microseconds is optional. Each element allows wildcard <code class="literal">*</code> values. Ranges can be specified
					by means of lower bounds then a colon ‘:’ then the upper bound. The division operator <code class="literal">*/x</code> can be used to
					specify that every x<sub>th</sub> value is valid. Combinations of these operators can be used by placing these into square brackets ([]).
				</p>
				<p>
					The <code class="literal">timer:at</code> observer may also be parameterized by an expression that contains one or more references to properties of prior events in the same pattern, or may also reference variables, substitution parameters or any other expression returning a numeric value. The frequency division operator <code class="literal">*/x</code> and parameters lists within brackets ([]) are an exception: they may only contain variables, substitution parameters or numeric values.
				</p>
				<p>
					This expression pattern matches every 5 minutes past the hour.
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every timer:at(5, *, *, *, *)</pre>
				<p>
					The below <code class="literal">timer:at</code> pattern matches every 15 minutes from 8am to 5:45pm (hours 8 to 17 at 0, 15, 30 and 45 minutes past the hour) on even numbered days of the month as well as on the
					first day of the month.
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">timer:at (*/15, 8:17, [*/2, 1], *, *)</pre>
				<p>
					The below table outlines the fields, valid values and keywords available for each field:
				</p>
				<div class="table"><a id="d0e22469"></a>
					<p class="title"><b>Table 7.5. Crontab Fields</b></p>
					<div class="table-contents">
						<table summary="Crontab Fields" border="1">
							<colgroup>
								<col>
								<col>
								<col>
								<col>
							</colgroup>
							<thead>
								<tr>
									<th>Field Name</th>
									<th>Mandatory?</th>
									<th>Allowed Values</th>
									<th>Additional Keywords</th>
								</tr>
							</thead>
							<tbody>
								<tr>
									<td>Minutes</td>
									<td>yes</td>
									<td>0 - 59</td>
									<td> </td>
								</tr>
								<tr>
									<td>Hours</td>
									<td>yes</td>
									<td>0 - 23</td>
									<td> </td>
								</tr>
								<tr>
									<td>Days Of Month</td>
									<td>yes</td>
									<td>1 - 31</td>
									<td>last, weekday, lastweekday</td>
								</tr>
								<tr>
									<td>Months</td>
									<td>yes</td>
									<td>1 - 12</td>
									<td> </td>
								</tr>
								<tr>
									<td>Days Of Week</td>
									<td>yes</td>
									<td>0 (Sunday) - 6 (Saturday)</td>
									<td>last</td>
								</tr>
								<tr>
									<td>Seconds</td>
									<td>no (required if specifying a time zone, milliseconds or microseconds)</td>
									<td>0 - 59</td>
									<td> </td>
								</tr>
								<tr>
									<td>Time Zone</td>
									<td>no (required if specifying milliseconds or microseconds)</td>
									<td>any string (not validated, see TimeZone javadoc; use <code class="literal">*</code> for any value)</td>
									<td> </td>
								</tr>
								<tr>
									<td>Milliseconds</td>
									<td>no (required if specifying microseconds)</td>
									<td>0 - 999</td>
									<td> </td>
								</tr>
								<tr>
									<td>Microseconds</td>
									<td>no</td>
									<td>0 - 999 (only relevant when using microseconds as the runtime time unit)</td>
									<td> </td>
								</tr>
							</tbody>
						</table>
					</div>
				</div><br class="table-break">
				<p>
					The keyword <code class="literal">last</code> used in the days-of-month field means the last day of the month (current month). To specify the last day of another month, you must provide a value for the month field. For example: <code class="literal">timer:at(*, *, last,2,*)</code> is the last day of February.
				</p>
				<p>
					The <code class="literal">last</code> keyword in the day-of-week field by itself simply means Saturday. If used in the day-of-week field after another value, it means "the last xxx day of the month" - for example "5 last" means "the last Friday of the month".
					So the last Friday of the current month will be: <code class="literal">timer:at(*, *, *, *, 5 last)</code>. And the last Friday of June: <code class="literal">timer:at(*, *, *, 6, 5 last)</code>.
				</p>
				<p>
					The keyword <code class="literal">weekday</code> is used to specify the weekday (Monday-Friday) nearest the given day. Variant could include month like in: <code class="literal">timer:at(*, *, 30 weekday, 9, *)</code> which for year 2007 is Friday September 28th (no jump over month).
				</p>
				<p>
					The keyword <code class="literal">lastweekday</code> is a combination of two parameters, the <code class="literal">last</code> and the <code class="literal">weekday</code> keywords. A typical example could be: <code class="literal">timer:at(*, *, *, lastweekday, 9, *)</code> which will define Friday September 28th (example year is 2007).
				</p>
				<p>
					The time zone is a string-type value that specifies the time zone of the schedule. You must specify a value for seconds when specifying a time zone. The runtime relies on the <code class="literal">java.util.TimeZone</code> to interpret the time zone value. Note that <code class="literal">TimeZone</code> does not validate time zone strings.
				</p>
				<p>
					The following <code class="literal">timer:at</code> pattern matches at 5:00 pm Pacific Standard Time (PST):
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">timer:at (0, 17, *, *, *, *, 'PST')</pre>
				<p>
					Any expression may occur among the parameters. This example invokes a user-defined function <code class="literal">computeHour</code> to return an hour:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">timer:at (0, computeHour(), *, *, *, *)</pre>
				<p>
					The following restrictions apply to crontab parameters:
				</p>
				<div class="itemizedlist">
					<ul compact="compact">
						<li>
							<p>
								It is not possible to specify both Days Of Month and Days Of Week.
							</p>
						</li>
					</ul>
				</div>
				<p>
					The return value for method that returns a crontab wildcard is <code class="literal">WildcardParameter</code> and for a crontab range is <code class="literal">RangeParameter</code>.
				</p>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-timer-at-every"></a>7.6.4.1. timer:at and the <code class="literal">every</code> Operator</h4>
							</div>
						</div>
					</div>
					<p>
						When using <code class="literal">timer:at</code> with the <code class="literal">every</code> operator the crontab-like timer computes the next time at which the timer should fire based on the specification and the current time. When using <code class="literal">every</code>, the current time is the time the timer fired or the statement start time if the timer has not fired once.
					</p>
					<p>
						For example, this pattern fires every 1 minute starting at 1:00pm and ending at 1:59pm, every day:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every timer:at(*, 13, *, *, *)</pre>
					<p>
						Assume the above statement gets started at 1:05pm and 20 seconds. In such case the above pattern fires every 1 minute starting at 1:06pm and ending at 1:59pm for that day and 1:00pm to 1:59pm every following day.
					</p>
					<p>
						To get the pattern to fire only once at 1pm every day, explicitly specify the minute to start. The pattern below fires every day at 1:00pm:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every timer:at(0, 13, *, *, *)</pre>
					<p>
						By specifying a second resolution the timer can be made to fire every second, for instance:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every timer:at(*, *, *, *, *, *)</pre>
				</div>
			</div>
			<div class="sect2" lang="en-US">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title"><a id="pattern-timer-schedule"></a>7.6.5. Schedule (<code class="literal">timer:schedule</code>)</h3>
						</div>
					</div>
				</div><a id="d0e22679" class="indexterm"></a><a id="d0e22684" class="indexterm"></a>
				<p>
					The <code class="literal">timer:schedule</code> observer is a flexible observer for scheduling.
				</p>
				<p>
					The observer implements relevant parts of the ISO 8601 specification however it is not necessary to use ISO 8601 formats.
					The ISO 8601 standard is an international standard covering the exchange of date and time-related data.
					The standard specifies a date format, a format for time periods and a format for specifying the number of repetitions.
					Please find more information on ISO 8601 at <a class="link" href="http://en.wikipedia.org/wiki/ISO_8601" target="">Wikipedia</a>.
				</p>
				<p>
					The observer takes the following named parameters:
				</p>
				<div class="table"><a id="d0e22701"></a>
					<p class="title"><b>Table 7.6. Timer Schedule Parameters</b></p>
					<div class="table-contents">
						<table summary="Timer Schedule Parameters" border="1">
							<colgroup>
								<col>
								<col>
							</colgroup>
							<thead>
								<tr>
									<th>Name</th>
									<th>Description</th>
								</tr>
							</thead>
							<tbody>
								<tr>
									<td><code class="literal">iso</code></td>
									<td>An expression returning a string-type ISO 8601 formatted date, time period and/or number of repetitions.</td>
								</tr>
								<tr>
									<td><code class="literal">repetitions</code></td>
									<td>An expression returning a numeric value that specifies a number of repetitions. Provide a value of <code class="literal">-1</code> for an unlimited number of repetitions.
										If unspecified, the number of repetitions is one.</td>
								</tr>
								<tr>
									<td><code class="literal">date</code></td>
									<td>An expression returning a string-type ISO 8601 formatted date, or an expression that returns any of these types:
										<code class="literal">long</code>, <code class="literal">Date</code>, <code class="literal">Calendar</code>, <code class="literal">LocalDateTime</code>, <code class="literal">ZonedDateTime</code>.
									</td>
								</tr>
								<tr>
									<td><code class="literal">period</code></td>
									<td>An expression returning a time period, see <a class="xref" href="epl_clauses.html#epl-syntax-time-periods" title="5.2.1. Specifying Time Periods">Section 5.2.1, “Specifying Time Periods”</a></td>
								</tr>
							</tbody>
						</table>
					</div>
				</div><br class="table-break">
				<p>
					In summary, for example, the below pattern schedules two callbacks: The first callback 2008-03-01 at 13:00:00 UTC and the second callback on 2009-05-11 at 15:30:00 UTC.
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">select * from pattern[every timer:schedule(iso: 'R2/2008-03-01T13:00:00Z/P1Y2M10DT2H30M')]</pre>
				<p>
					The number of repetitions, date and period can be separated and do not have to be ISO 8601 strings, allowing each part to be an own expression.
				</p>
				<p>
					This example specifies separate expressions. The equivalent schedule to the above example is:
				</p>
				<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">select * from pattern[every timer:schedule(repetitions: 2, date: '2008-03-01T13:00:00Z', period: 1 year 2 month 10 days 2 hours 30 minutes)]</pre>
				<p>
					When providing the <code class="literal">iso</code> parameter, it must be the only parameter. The <code class="literal">repetitions</code> parameter is only allowed in conjunction with other parameters.
				</p>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-timer-schedule-specify"></a>7.6.5.1. Specifying ISO8601 Dates, Periods and Repetition</h4>
							</div>
						</div>
					</div>
					<div class="sect4" lang="en-US">
						<div class="titlepage">
							<div>
								<div>
									<h5 class="title"><a id="pattern-timer-schedule-date"></a>7.6.5.1.1. Specifying Dates</h5>
								</div>
							</div>
						</div>
						<p>
							The complete document for ISO 8601, the international standard for the representation of dates and times, can be found at
							<a class="link" href="http://www.w3.org/TR/NOTE-datetime" target="">http://www.w3.org/TR/NOTE-datetime</a>.
						</p>
						<p>
							The supported ISO 8601 date formats are:
						</p>
						<div class="table"><a id="d0e22789"></a>
							<p class="title"><b>Table 7.7. ISO 8601 Period Examples</b></p>
							<div class="table-contents">
								<table summary="ISO 8601 Period Examples" border="1">
									<colgroup>
										<col>
										<col>
										<col>
									</colgroup>
									<thead>
										<tr>
											<th>Description</th>
											<th>Format</th>
											<th>Example</th>
										</tr>
									</thead>
									<tbody>
										<tr>
											<td>Complete date plus hours, minutes and seconds (zero milliseconds, zero microseconds):</td>
											<td><code class="literal">YYYY-MM-DDThh:mm:ssTZD</code></td>
											<td>
												<p><code class="literal">1997-07-16T19:20:30Z</code></p>
												<p>(i.e. GMT+00:00, UTC)</p>
												<p><code class="literal">1997-07-16T19:20:30+01:00</code></p>
												<p>(i.e. GMT+01:00)</p>
												<p><code class="literal">1997-07-16T19:20:30</code></p>
												<p>(i.e. local time zone)</p>
											</td>
										</tr>
										<tr>
											<td>Complete date plus hours, minutes, seconds and a decimal fraction of a second (zero microseconds)</td>
											<td><code class="literal">YYYY-MM-DDThh:mm:ss.sTZD</code></td>
											<td>
												<p><code class="literal">1997-07-16T19:20:30.45Z</code></p>
												<p>(i.e. GMT+00:00, UTC)</p>
												<p><code class="literal">1997-07-16T19:20:30.45+01:00</code></p>
												<p>(i.e. GMT+01:00)</p>
												<p><code class="literal">1997-07-16T19:20:30.45</code></p>
												<p>(i.e. local time zone)</p>
											</td>
										</tr>
									</tbody>
								</table>
							</div>
						</div><br class="table-break">
					</div>
					<div class="sect4" lang="en-US">
						<div class="titlepage">
							<div>
								<div>
									<h5 class="title"><a id="pattern-timer-schedule-periods"></a>7.6.5.1.2. Specifying Periods</h5>
								</div>
							</div>
						</div>
						<p>
							In ISO 8601, periods are specified by a <code class="literal">P</code> and an optional year, month, week and day count. If there is a time part, add <code class="literal">T</code> and optionally provide the hour, minute and seconds. The format does not have any whitespace. The synopsis is:
						</p>
						<pre class="synopsis">P [<span class="emphasis"><em>n</em></span>Y] [<span class="emphasis"><em>n</em></span>M] [<span class="emphasis"><em>n</em></span>W] [<span class="emphasis"><em>n</em></span>D] [T [<span class="emphasis"><em>n</em></span>H [<span class="emphasis"><em>n</em></span>M] [<span class="emphasis"><em>n</em></span>S] ]</pre>
						<p>
							The <code class="literal">Y</code> stands for years, the <code class="literal">M</code> for month as well as minutes, the <code class="literal">W</code> for weeks and the D for days.
							The <code class="literal">H</code> stands for hours and the <code class="literal">S</code> means seconds.
						</p>
						<div class="table"><a id="d0e22914"></a>
							<p class="title"><b>Table 7.8. ISO 8601 Period Examples</b></p>
							<div class="table-contents">
								<table summary="ISO 8601 Period Examples" border="1">
									<colgroup>
										<col>
										<col>
									</colgroup>
									<thead>
										<tr>
											<th>Example</th>
											<th>Description</th>
										</tr>
									</thead>
									<tbody>
										<tr>
											<td>P10M</td>
											<td>10 months</td>
										</tr>
										<tr>
											<td>PT10M</td>
											<td>10 minutes</td>
										</tr>
										<tr>
											<td>P1Y3M12D</td>
											<td>1 year, 3 month and 12 days</td>
										</tr>
										<tr>
											<td>P10DT5M</td>
											<td>10 days and 5 minutes</td>
										</tr>
										<tr>
											<td>P1Y2M3DT4H5M6S</td>
											<td>1 year, 2 month, 3 days, 4 hours, 5 minutes, 6 seconds</td>
										</tr>
									</tbody>
								</table>
							</div>
						</div><br class="table-break">
					</div>
					<div class="sect4" lang="en-US">
						<div class="titlepage">
							<div>
								<div>
									<h5 class="title"><a id="pattern-timer-schedule-repetition"></a>7.6.5.1.3. Specifying Repetitions</h5>
								</div>
							</div>
						</div>
						<p>
							In ISO 8601, repetition is specified by an <code class="literal">R</code> and an optional number of repetitions without any white space. The synopsis is:
						</p>
						<pre class="synopsis">R [<span class="emphasis"><em>nn</em></span>]</pre>
						<p>
							For example <code class="literal">R5</code> means 5 repetitions, and just <code class="literal">R</code> means unlimited repetitions.
						</p>
					</div>
				</div>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-timer-schedule-scheduleatdate"></a>7.6.5.2. Scheduling a Callback to Occur for a Given Date (Non-Repeating)</h4>
							</div>
						</div>
					</div>
					<p>
						To instruct the runtime to observe a date, provide a date to the observer.
						When time advances to the specified date, the pattern subexpression fires.
					</p>
					<p>
						For example, this pattern fires once when time reaches 2012-10-01 at 5:52:00 (UTC):
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">timer:schedule(iso:'2012-10-01T05:52:00Z')</pre>
					<p>
						This equivalent pattern specifies separate expressions:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every timer:schedule(date: '2012-10-01T05:52:00Z')</pre>
					<p>
						When the observer fires, the pattern subexpression becomes permanently false and the runtime does not restart the observer.
					</p>
					<p>
						If the provided date is a past date as compared to runtime time, the pattern subexpression becomes permanently false on start.
					</p>
				</div>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-timer-schedule-scheduleafterperiod"></a>7.6.5.3. Scheduling a Callback to Occur After a Given Period (Non-Repeating)</h4>
							</div>
						</div>
					</div>
					<p>
						To instruct the runtime to observe a period starting from the current runtime time, provide a period.
						When time advances to the current runtime time plus the specified period, the pattern subexpression fires.
					</p>
					<p>
						Assuming the current runtime time is 2012-10-01 at 5:52:00 (UTC), this pattern fires once when time reaches 5:53:00:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">timer:schedule(iso:'PT1M')</pre>
					<p>
						This equivalent pattern specifies separate expressions:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every timer:schedule(period: 1 minute)</pre>
					<p>
						When the observer fires, the pattern subexpression becomes permanently false and the runtime does not restart the observer.
					</p>
				</div>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-timer-schedule-scheduleafterdateandperiod"></a>7.6.5.4. Scheduling a Callback to Occur After a Given Date and Period (Non-Repeating)</h4>
							</div>
						</div>
					</div>
					<p>
						To instruct the runtime to observe a period starting from a given date, provide a date and a period.
						When time advances to the date plus the specified period, the pattern subexpression fires.
					</p>
					<p>
						Assuming the current runtime time is 5:52:00 (UTC), this pattern fires once when time reaches 2012-10-01 at 5:53:00:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">timer:schedule(iso:'2012-10-01T05:52:00Z/PT1M')</pre>
					<p>
						This equivalent pattern specifies separate expressions:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every timer:schedule(date: '2012-10-01T05:52:00Z', period: 1 minute)</pre>
					<p>
						When the observer fires, the pattern subexpression becomes permanently false and the runtime does not restart the observer.
					</p>
				</div>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-timer-schedule-scheduleperiodicallyanchorruntimetime"></a>7.6.5.5. Scheduling a Callback to Occur Periodically (Repeating)</h4>
							</div>
						</div>
					</div>
					<p>
						To instruct the runtime to observe a period starting from the current runtime time and repeatedly thereafter anchored to current runtime time,
						provide a number of repetitions and a period (see synopsis provided earlier), like this:
					</p>
					<pre class="synopsis"><span class="emphasis"><em>repetitions</em></span>/<span class="emphasis"><em>period</em></span></pre>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">timer:schedule(iso: 'R2/PT1M')</pre>
					<p>
						When time advances to the current runtime time plus the specified period, the pattern subexpression fires for the first time.
						Repeatedly when time advances to the current runtime time plus a multiple of the specified period, the pattern subexpression fires, up to the number of repetitions specified (if any).
					</p>
					<p>
						This pattern specifies a repetition of two. Assuming the current runtime time is 2012-10-01 at 5:52:00 (UTC), it fires when time reaches 5:53:00 and again when time reaches 5:54:00:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every timer:schedule(iso: 'R2/PT1M')</pre>
					<p>
						This equivalent pattern specifies separate expressions:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every timer:schedule(repetitions: 2, period: 1 minute)</pre>
					<p>
						All schedule computations are relative to (i.e. anchored to) current runtime time at observer start.
						Once the number of repetitions is reached relative to the current runtime time at observer start, the pattern subexpression becomes permanently false and the runtime does not restart the observer.
					</p>
					<div xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="note">
						<h2>Note</h2>
						<p>
							Please specify the <code class="literal">every</code> operator for repeating schedules.
						</p>
					</div>
				</div>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-timer-schedule-scheduleperiodicallyanchordate"></a>7.6.5.6. Scheduling a Callback to Occur Periodically Starting From a Given Date (Repeating)</h4>
							</div>
						</div>
					</div>
					<p>
						To instruct the runtime to observe a period starting from a given date and repeatedly thereafter anchored to the provide date,
						provide a number of repetitions and a date and a period (see synopsis provided earlier), like this:
					</p>
					<pre class="synopsis"><span class="emphasis"><em>repetitions</em></span>/<span class="emphasis"><em>date</em></span>/<span class="emphasis"><em>period</em></span></pre>
					<p>
						When time advances to the date, the pattern subexpression fires for the first time.
						You may specify a date older than current runtime time as an anchor.
						Repeatedly when time advances to the date plus a multiple of the specified period, the pattern subexpression fires, up to the number of repetitions specified (if any).
					</p>
					<p>
						This pattern specifies a repetition of two. The pattern fires when time reaches 2012-10-01 at 5:52:00 (UTC) and again when time reaches 5:53:00.
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every timer:schedule(iso: 'R2/2012-10-01T05:52:00Z/PT1M')</pre>
					<p>
						This equivalent pattern specifies separate expressions:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every timer:schedule(repetitions: 2, date:'2012-10-01T05:52:00Z', period: 1 minute)</pre>
					<p>
						All schedule computations are relative to (i.e. anchored to) the provided date.
						Once the number of repetitions is reached relative to the provided date, the pattern subexpression becomes permanently false and the runtime does not restart the observer.
					</p>
					<div xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="note">
						<h2>Note</h2>
						<p>
							Please specify the <code class="literal">every</code> operator for repeating schedules.
						</p>
					</div>
				</div>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-timer-schedule-examples"></a>7.6.5.7. Additional Usage Examples</h4>
							</div>
						</div>
					</div>
					<p>
						The pattern below outputs every <code class="literal">MyEvent</code> event after the MyEvent arrived and upon the next round 15 seconds:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">select * from pattern[every e=MyEvent -&gt; timer:schedule(iso: 'R/1980-01-01T00:00:00Z/PT15S']</pre>
					<p>
						Assuming a <code class="literal">MyEvent</code> event arrives on 2012-10-01 at 5:51:07 the output for that event occurs at 5:51:15.
					</p>
					<p>
						All parameters can be expressions. The <code class="literal">date</code> parameter could, for example, be used with <code class="literal">current_timestamp</code>
						to compute a schedule:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">select * from pattern[date: current_timestamp.withTime(9, 0, 0, 0)]</pre>
					<p>
						The above statement fires only at 9am and not after 9am on the same day (one repetition).
					</p>
				</div>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-timer-schedule-equivalent"></a>7.6.5.8. Samples With Equivalent EPL</h4>
							</div>
						</div>
					</div>
					<p>
						The following EPL is equivalent:
					</p>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">select * from pattern[every timer:schedule(iso: 'R2/2008-03-01T13:00:00Z/P1Y2M10DT2H30M')]</pre>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">select * from pattern[every (timer:schedule(iso: '2008-03-01T13:00:00Z') or timer:schedule(iso: '2009-05-11T15:30:00Z'))]</pre>
					<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">select * from pattern[every (timer:schedule(iso: '2008-03-01T13:00:00Z') or timer:schedule(iso: '2008-03-01T13:00:00Z/P1Y2M10DT2H30M'))]</pre>
				</div>
				<div class="sect3" lang="en-US">
					<div class="titlepage">
						<div>
							<div>
								<h4 class="title"><a id="pattern-timer-schedule-implementation"></a>7.6.5.9. Implementation Notes</h4>
							</div>
						</div>
					</div>
					<p>
						Your environment should have the JAXB date parser available. The runtime uses <code class="literal">javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(dateText).toGregorianCalendar()</code> for date parsing.
					</p>
				</div>
			</div>
		</div>
		<div class="sect1" lang="en-US">
			<div class="titlepage">
				<div>
					<div>
						<h2 class="title"><a id="pattern-walkthrough"></a>7.7. Event Pattern Walkthrough</h2>
					</div>
				</div>
			</div><a id="d0e23132" class="indexterm"></a>
			<p>
				This walkthrough discusses the following pattern:
			</p>
			<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">every a=LoginEvent -&gt; (timer:interval(1 min) and not LogoutEvent(userId=a.userId))]</pre>
			<p>
				This pattern detects when a <code class="literal">LoginEvent</code> is not followed by a <code class="literal">LogoutEvent</code> arriving within 1 minute of the <code class="literal">LoginEvent</code>.
			</p>
			<p>
				The runtime parses the pattern expression and builds a expression tree. At the root of the expression tree, for this specific pattern, is the followed-by (<code class="literal">-&gt;</code>) operator as followed-by has the lowest precedence (see precedence).
			</p>
			<p>
				The pattern expression tree looks like this.
			</p>
			<pre xmlns="" xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="">
Followed-by operator (-&gt;)
  |
  | ---- Every
  |       |
  |       | ---- a=LoginEvent
  |
  | ---- And
          |
          | ---- timer:interval(1 min)
          |                  
          | ---- Not
                 |
                 | ---- LogoutEvent(userId=a.userId)</pre>
			<p>
				The followed-by (<code class="literal">-&gt;</code>) operator has two subexpressions that it manages, the <code class="literal">Every</code> expression that itself has the <code class="literal">a=LoginEvent</code> subexpression as a child, and the <code class="literal">And</code> expression that itself has two subexpressions as children.
			</p>
			<p>
				When the runtime activates a pattern or pattern subexpression, it activates it from a top-down direction. In this example the runtime activates the followed-by (<code class="literal">-&gt;</code>) expression.
				The followed-by expression activates only its own left-most subexpression, which is the <code class="literal">Every</code> expression. The <code class="literal">Every</code> expression in turn activates the <code class="literal">a=LoginEvent</code> subexpression which registers a filter looking for a <code class="literal">LoginEvent</code> in the global filter index (see <a class="xref" href="processingmodel.html#processingmodel_indexes_filterindexes" title="2.18.2. Filter Indexes">Section 2.18.2, “Filter Indexes”</a>).
			</p>
			<p>
				In this example, the <code class="literal">And</code> subexpression and its subexpressions do not get activated. Therefore after this pattern initially activates there is no
				filter active time looking for <code class="literal">LogoutEvent</code> event and there is no time tracking of any kind at this point.
			</p>
			<p>
				Let time t<sub>0</sub> be the time of statement deployment. As discussed, upon deployment of the statement the runtime activates the pattern subexpression <code class="literal">every a=LoginEvent</code> only. At this time there is 1 active subexpression:
			</p>
			<div xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="orderedlist">
				<ol>
					<li>
						<p>
							<code class="literal">every a=LoginEvent</code>
						</p>
					</li>
				</ol>
			</div>
			<p>
				As you can see, the tree of active subexpressions (the tree of states) is not the same as the tree of expressions. After the pattern activated there are no active subexpressions (no states) for the <code class="literal">And</code>-part of the example expression tree.
			</p>
			<p>
				Let's assume that at time t<sub>1</sub> a <code class="literal">LoginEvent</code> with user id 10 arrives.
				This causes the <code class="literal">a=LoginEvent</code> subexpression to become true. In turn, this causes the <code class="literal">Every</code> subexpression to become true. This causes the left-hand-side of the followed-by subexpression to become true. This in turn causes activation of the <code class="literal">And</code> subexpression.
			</p>
			<p>
				The activation of the <code class="literal">And</code>-subexpression causes activation of both <code class="literal">timer:interval(1 min)</code> (from t<sub>1</sub>) and the <code class="literal">Not</code>-subexpression.
				The activation of the <code class="literal">And</code>-subexpression registers a filter looking for a <code class="literal">LogoutEvent</code> that has a user id value of 10 in the global filter index
				and registers a timer callback for t<sub>1</sub>+1 minute.
			</p>
			<p>
				The runtime does not terminate the subexpression <code class="literal">a=LoginEvent</code> as it lives under an <code class="literal">Every</code> operator which means it should keep looking for
				more <code class="literal">LoginEvent</code> events.
			</p>
			<p>
				There now are 2 active subexpressions:
			</p>
			<div xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="orderedlist">
				<ol>
					<li>
						<p>
							<code class="literal">every a=LoginEvent</code>
						</p>
					</li>
					<li>
						<p>
							<code class="literal">timer:interval(t1+1 min) and not LogoutEvent(userId=10)</code>
						</p>
					</li>
				</ol>
			</div>
			<p>
				Let's assume that at time t<sub>2</sub> another <code class="literal">LoginEvent</code> with user id 20 arrives (assume t<sub>2</sub> – t<sub>1</sub> &lt; 1 min).
				This again causes the <code class="literal">a=LoginEvent</code> subexpression to become true. In turn, this causes the <code class="literal">Every</code> subexpression to become true. This causes the left-hand-side of the followed-by subexpression to become true. This in turn causes activation of the <code class="literal">And</code> subexpression.
			</p>
			<p>
				The activation of the <code class="literal">And</code>-subexpression causes activation of both <code class="literal">timer:interval(1 min)</code> (from t<sub>2</sub>) and the <code class="literal">Not</code>-subexpression.
				The activation of the <code class="literal">And</code>-subexpression registers a filter looking for a <code class="literal">LogoutEvent</code> that has a user id value of 20 in the global filter index
				and registers a timer callback for t<sub>2</sub>+1 minute.
			</p>
			<p>
				There now are 3 active subexpressions:
			</p>
			<div xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="orderedlist">
				<ol>
					<li>
						<p>
							<code class="literal">every a=LoginEvent</code>
						</p>
					</li>
					<li>
						<p>
							<code class="literal">timer:interval(t1+1 min) and not LogoutEvent(userId=10)</code>
						</p>
					</li>
					<li>
						<p>
							<code class="literal">timer:interval(t2+1 min) and not LogoutEvent(userId=20)</code>
						</p>
					</li>
				</ol>
			</div>
			<p>
				In this scenario at time t<sub>3</sub> one minute has passed since t<sub>1</sub> and a matching <code class="literal">LogoutEvent</code> was not received.
			</p>
			<p>
				The subexpression <code class="literal">timer:interval(t1+1 min)</code> becomes true. In turn, this causes the <code class="literal">And</code>-subexpression to become true as the <code class="literal">Not</code>-subexpression is already true on start. In turn, this causes the followed-by subexpression to become true. In turn, this causes an output of the pattern match.
			</p>
			<p>
				The runtime terminates the subexpression <code class="literal">not LogoutEvent(userId=10)</code> which unregisters the filter looking for a <code class="literal">LogoutEvent</code> that has a user id value of 10 from the global filter index.
			</p>
			<p>
				There now are 2 active subexpressions:
			</p>
			<div xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="orderedlist">
				<ol>
					<li>
						<p>
							<code class="literal">every a=LoginEvent</code>
						</p>
					</li>
					<li>
						<p>
							<code class="literal">timer:interval(t2+1 min) and not LogoutEvent(userId=20)</code>
						</p>
					</li>
				</ol>
			</div>
			<p>
				Let's assume that at time t<sub>4</sub> a <code class="literal">LogoutEvent</code> with user id 20 arrives (assume t<sub>4</sub> – t<sub>2</sub> &lt; 1 min).
				This again causes the <code class="literal">LogoutEvent(userId=20)</code> subexpression to become true. In turn, this causes the <code class="literal">Not</code> subexpression to become permanently false (as <code class="literal">Not</code> reverses the truth value). This causes the <code class="literal">And</code>-subexpression to become permanently false.
				This causes the pattern subexpression <code class="literal">timer:interval(t2+1 min) and not LogoutEvent(userId=20)</code> to terminate which causes the timer callback t<sub>2</sub>+1 minute to unregister.
			</p>
			<p>
				Finally there is 1 active subexpression remaining:
			</p>
			<div xmlns:d="http://docbook.org/ns/docbook" xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="orderedlist">
				<ol>
					<li>
						<p>
							<code class="literal">every a=LoginEvent</code>
						</p>
					</li>
				</ol>
			</div>
		</div>
	</div>
	<ul xmlns:d="http://docbook.org/ns/docbook" class="docnav">
		<li class="previous"><a accesskey="p" href="nwtable.html"><strong>Prev</strong>Chapter 6. EPL Reference: Named Windows and Tables</a></li>
		<li class="up"><a accesskey="u" href="#"><strong>Top of page</strong></a></li>
		<li class="home"><a accesskey="h" href="index.html"><strong>Front page</strong></a></li>
		<li class="next"><a accesskey="n" href="match-recognize.html"><strong>Next</strong>Chapter 8. EPL Reference: Match Recognize</a></li>
	</ul>
</body>

</html>